For me it was:

sudo apt-get remove openjdk-6*
sudo apt-get remove icedtea*
Answer from DavidGamba on Stack Exchange
Top answer
1 of 3
11

For me it was:

sudo apt-get remove openjdk-6*
sudo apt-get remove icedtea*
2 of 3
3

I came across this because I am working through an instructional book for android programming which wants to use a specific Java SE and JRE (8u121) and requests that all other java packages be removed before continuing with the installation. So after reading the above ideas I went with:

sudo apt-get remove openjdk*

and the result was:

bryan@kali:~$ java -version
bash: /usr/bin/java: No such file or directory

So the above suggests that there is no java found of any version. Which is the OP wanted to do (I think).

In case somebody finds this thread because they are uninstalling Java so that they can install an Old Version, I have included a walk-through I found. The first two codes help you install it if you had no GUI. If you have a tarball then skip those. The last codeblock has some parts that you'll need to edit if you are not installing my same version.


{begin copy/paste}

In case that you are attempting to install Java JDK remotely and have absolutely no access to Graphical User Interface and web browser use the following curl method to download Java JDK using a command line.

First, obtain a correct download URL by using the curl command:

$ curl -s http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html | grep "otn-pub" | cut -d \" -f12

The above command outputs a bunch of URLs for your selection. To initiate the download of the desired Java file, copy its URL and start the download using the curl command while accepting the requested Jave license. For example:

$ curl -LOb "oraclelicense=a" http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz

Install Java JDK At this stage, we should have an appropriate Java JDK tarball within our current working directory:

$ ls
jdk-8u121-linux-x64.tar.gz

Create a target Java JDK installation directory:

# mkdir /opt/java-jdk

Extract the previously downloaded Java JDK tarball:

# tar -C /opt/java-jdk -zxf jdk-8u121-linux-x64.tar.gz

Set Oracle Java as default Currently, the system does not recognise our Java JDK installation:

$ update-alternatives --list java
update-alternatives: error: no alternatives for java
$ java
bash: java: command not found

Use the update-alternatives command to inlcude both, java and javac as part of the system's Java environment.Please replace the below path to java binaries where appropriate to reflect your downloaded java version:

# update-alternatives --install /usr/bin/java java /opt/java-jdk/jdk1.8.0_121/bin/java 1   
update-alternatives: using /opt/java-jdk/jdk1.8.0_121/bin/java to provide /usr/bin/java (java) in auto mode
# update-alternatives --install /usr/bin/javac javac /opt/java-jdk/jdk1.8.0_121/bin/javac 1
update-alternatives: using /opt/java-jdk/jdk1.8.0_121/bin/javac to provide /usr/bin/javac (javac) in auto mode

{end copy/paste}

Okay so after I followed that I wanted to confirm that it works...

bryan@kali:~/Desktop$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

That's it! That's what we want.

Then I became concerned that it 'apt update' may just undo what I did by updating the package (unsure). So I put them on hold. To remove hold: apt-mark unhold.

bryan@kali:~/Desktop$ sudo apt-mark hold openjdk-8*
openjdk-8-jre set on hold.
openjdk-8-jre-headless set on hold.
openjdk-8-doc set on hold.
openjdk-8-jdk set on hold.
openjdk-8-dbg set on hold.
openjdk-8-demo set on hold.
openjdk-8-jdk-headless set on hold.
openjdk-8-source set on hold.
openjdk-8-jre-dcevm set on hold.
openjdk-8-jre-zero set on hold.
🌐
Oracle
java.com › en › download › help › linux_uninstall.html
How do I uninstall Java for Linux?
Example: ln -f /usr/lib/mozilla/plugins/libnpjp2.so If you want to completely remove Java from your Linux box, the procedure of removing the symbolic link is described below. ... There are two ways to uninstall Java. Please use the method that you used when you installed Java.
Discussions

How to uninstall versions of Java openJDK - Unix & Linux Stack Exchange
I am using Linux Mint XFCE 20. Recently I installed Java by running sudo apt-get install openjdk and it automatically installed versions 8 and 11 of both JRE and JDK, including JRE headless. It tur... More on unix.stackexchange.com
🌐 unix.stackexchange.com
February 1, 2021
linux - How to remove old version of Java and install new version - Stack Overflow
I have a Linux box on which Java 1.7 is installed: #java -version java version "1.7.0_09-icedtea" OpenJDK Runtime Environment (rhel-2.3.4.1.el6_3-x86_64) OpenJDK 64-Bit Server VM (build 23.2-b09, ... More on stackoverflow.com
🌐 stackoverflow.com
how to remove default-jre java installation from Ubuntu? - Stack Overflow
I had no java (i.e. java -version said java no found or similar) I installed it like this: sudo apt-get install default-jre This results in installing java 1.6 - I need java 1.7 So the next prob... More on stackoverflow.com
🌐 stackoverflow.com
help me uninstall java that is installed and work but not uninstallable by apt or snap???
[...] sudo apt purge OpenJDK [...] Linux is very, very case sensitive :-) Also, the command should be: sudo apt remove --purge openjdk <--- IF you installed it from a .deb package also see "sudo apt search openjdk" for a list of all the available packages which contain the "openjdk" string. sudo snap remove openjdk <--- IF you installed it as a snap also see "sudo snap list" and "sudo snap search openjdk" More on reddit.com
🌐 r/Ubuntu
3
1
October 29, 2024
🌐
Ultimate Systems Blog
blog.usro.net › ultimate systems blog › how-to › linux › how to uninstall java from debian
How to Uninstall Java from Debian – Ultimate Systems Blog
October 27, 2024 - Sometimes, we need to clean up our systems or simply remove software we no longer use. If you’re ready to say goodbye to Java on your Debian system, uninstalling it is straightforward. This guide covers everything from uninstalling a single version to removing multiple versions and cleaning ...
Top answer
1 of 9
424
  1. Remove all the Java related packages (Sun, Oracle, OpenJDK, IcedTea plugins, GIJ):

    dpkg-query -W -f='${binary:Package}\n' | grep -E -e '^(ia32-)?(sun|oracle)-java' -e '^openjdk-' -e '^icedtea' -e '^(default|gcj)-j(re|dk)' -e '^gcj-(.*)-j(re|dk)' -e '^java-common' | xargs sudo apt-get -y remove
    sudo apt-get -y autoremove
    
  2. Purge config files (careful. This command removed libsgutils2-2 and virtualbox config files too):

    dpkg -l | grep ^rc | awk '{print($2)}' | xargs sudo apt-get -y purge
    
  3. Remove Java config and cache directory:

    sudo bash -c 'ls -d /home/*/.java' | xargs sudo rm -rf
    
  4. Remove manually installed JVMs:

    sudo rm -rf /usr/lib/jvm/*
    
  5. Remove Java entries, if there is still any, from the alternatives:

    for g in ControlPanel java java_vm javaws jcontrol jexec keytool mozilla-javaplugin.so orbd pack200 policytool rmid rmiregistry servertool tnameserv unpack200 appletviewer apt extcheck HtmlConverter idlj jar jarsigner javac javadoc javah javap jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc xulrunner-1.9-javaplugin.so; do sudo update-alternatives --remove-all $g; done
    
  6. Search for possible remaining Java directories:

    sudo updatedb
    sudo locate -b '\pack200'
    

    If the command above produces any output like /path/to/jre1.6.0_34/bin/pack200 remove the directory that is parent of bin, like this: sudo rm -rf /path/to/jre1.6.0_34.

2 of 9
51

To completely remove OpenJDK on Ubuntu 11.10 (this may or may not be sufficient on other versions of Ubuntu), run:

sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*

If you want instructions for removing the proprietary Oracle ("Sun") version of Java, then you'll have to specify how you installed it. (If you edit your question to indicate this and leave a comment to this answer, I'll try to add information about how to remove that too.)

🌐
YouTube
youtube.com › watch
How to uninstall java in Ubuntu - Debian Linux | How to completely uninstall Java jdk? | Arjun Codes - YouTube
In this video i have shown How can I completely remove all traces of Java on my system? Remove all the versions of java available on your ubuntu or linux ope...
Published   July 5, 2021
🌐
Novice Stuffs
novicestuffs.wordpress.com › 2017 › 04 › 25 › how-to-uninstall-java-from-linux
How To Uninstall JDK From Linux ? – Novice Stuffs
December 28, 2017 - This tutorial is written to help New Linux Users, who want to uninstall Java Development Kit (JDK) installed on their Linux. The tasks performed on Ubuntu 16.04, but this will also work on other Debian Based Linux like Linux Mint, Kali Linux, etc. So, first of all, check the vendor of the JDK ...
Find elsewhere
🌐
2DayGeek
2daygeek.com › home › how to uninstall (oracle java & openjdk) in linux
How to remove/uninstall (oracle java & openjdk) in linux | 2DayGeek
May 26, 2021 - You may need to run these commands based on section'3.a' to uninstall ‘Oracle Java’ or ‘OpenJDK’ in Ubuntu/Debian systems:
🌐
MakeUseOf
makeuseof.com › home › linux › how to install java on ubuntu and remove it when you’re done
How to Install Java on Ubuntu and Remove It When You’re Done
February 23, 2023 - To remove OpenJDK and OpenJRE, launch the terminal using Ctrl + Alt + T and issue the following command to remove Java from your system: ... Confirm the uninstallation process by typing y.
Top answer
1 of 5
28
  1. To remove OpenJDK (the one you've already installed)

    sudo apt-get purge openjdk-\*

  2. Make a new directory for your new JDK

    sudo mkdir -p /usr/local/java

  3. Copy the file to the directory (you should be in that file path)

    sudo cp -r jdk-8u45-linux-x64.tar.gz /usr/local/java/

  4. Extract the file

    sudo tar xvzf jdk-8u45-linux-x64.tar.gz

  5. You should add this to your PATH now. To do that:

    a. Open /etc/profile : sudo gedit /etc/profile

    b. Scroll down (the end) and add the path where your jdk was installed

    JAVA_HOME=/usr/local/java/jdk1.8.0_45 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin export JAVA_HOME export PATH

    Save and exit

  6. Inform your Linux system where your Oracle Java JDK/JRE is located.

    a. Notify the system that Oracle Java JRE is available for use

    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_45/bin/java" 1

    b. Notify the system that Oracle Java JDK is available for use

    sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_45/bin/javac" 1

    c. Notify the system that Oracle Java Web start is available for use

    sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_20/bin/javaws" 1

  7. Inform your Linux system that Oracle Java JDK/JRE must be the default Java.

    a. Set the java runtime environment for the system

    sudo update-alternatives --set java /usr/local/java/jdk1.8.0_45/bin/java

    b. Set the javac compiler for the system

    sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_45/bin/javac

    c. Set Java Web start for the system

    sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_20/bin/javaws

  8. Reload your system wide PATH

    source /etc/profile

  9. Check the new version and you're done!

    java -version

2 of 5
8

Just unpack the new Java version, for example into /opt. Then do

Copyexport JAVA_HOME=/opt/jdk1.8.0_45 
export PATH=$JAVA_HOME/bin:$PATH

Put these exports into the startup files for your shell and you should be set. It is not necessary to uninstall the Java 7 installation.

🌐
Linux Hint
linuxhint.com › uninstall-java-ubuntu
How to uninstall Java from Ubuntu – Linux Hint
In this guide, we learned how to identify which version you have on your PC and completely uninstall it. The rise of Python and security issues has hit the popularity of Java.
🌐
GitHub
gist.github.com › shafinmahmud › 876d256821ec206564a7bfa524ff3d2f
Completely Remove JAVA from Linux · GitHub
Completely Remove JAVA from Linux. GitHub Gist: instantly share code, notes, and snippets.
🌐
Debian
lists.debian.org › debian-user › 2015 › 01 › msg00094.html
Re: How to undo Java installation and settings
January 3, 2015 - > cd /etc/alternatives > ln -s /usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/IcedTeaPlugin.so >& mozilla-javaplugin.so rm /etc/alternatives/IcedTeaPlugin.so rm /etc/alternatives/mozilla-javaplugin.so > cd /usr/lib/mozilla/plugins/ > ln -s /etc/alternatives/mozilla-javaplugin.so > mozilla-javaplugin.so > ln -s /etc/alternatives/mozilla-javaplugin.so mozilla-javaplugin.so rm /usr/lib/mozilla/plugins/mozilla-javaplugin.so You may want to clean up anything left behind manually.
🌐
Learn Ubuntu
learnubuntu.com › uninstall-java
Uninstall Java From Ubuntu
April 11, 2023 - Got several Java packages on Ubuntu and now want to remove them? Here's how to uninstall Java from Ubuntu.
🌐
Its Linux FOSS
itslinuxfoss.com › completely-uninstall-java-linux
ItsLinuxFOSS - Tutorials on Linux, Programming & Technology
Linux Administrator? Programmer? Or a Technology Enthusiast? We have got you covered. From beginning to expert level guides in 7th grade writing...
🌐
Baeldung
baeldung.com › home › installation › removing old versions of java and installing new versions on linux
Removing Old Versions of Java and Installing New Versions on Linux | Baeldung on Linux
January 14, 2025 - Let’s identify the installed Java package name using a package manager, such as apt on Debian-based systems: ... ii openjdk-11-jdk-headless 11.0.17+8-1ubuntu2~22.04 amd64 OpenJDK Development Kit (JDK) ii openjdk-17-jdk-headless 17.0.8+7-1ubuntu2~22.04 amd64 OpenJDK Development Kit (JDK) The output shows that both Java 11 and Java 17 are installed. Let’s take note of these package names for the next step. Let’s replace <java-package-name> with the exact package name listed earlier to uninstall it.
🌐
LinuxVox
linuxvox.com › blog › uninstall-java-linux
Uninstalling Java on Linux: A Comprehensive Guide — linuxvox.com
Environment Variables: Linux uses environment variables like JAVA_HOME, PATH, and CLASSPATH to locate Java executables and libraries. The easiest and most recommended way to uninstall Java on Linux is by using the package manager.
🌐
Reddit
reddit.com › r/ubuntu › help me uninstall java that is installed and work but not uninstallable by apt or snap???
r/Ubuntu on Reddit: help me uninstall java that is installed and work but not uninstallable by apt or snap???
October 29, 2024 -

maxtrax@maxtrax-MS-7B89:~/Clanlord$ java -version

openjdk version "21.0.4" 2024-07-16

OpenJDK Runtime Environment (build 21.0.4+7-Ubuntu-1ubuntu224.04)

OpenJDK 64-Bit Server VM (build 21.0.4+7-Ubuntu-1ubuntu224.04, mixed mode, sharing)

maxtrax@maxtrax-MS-7B89:~/Clanlord$ sudo apt purge OpenJDK

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

E: Unable to locate package OpenJDK

maxtrax@maxtrax-MS-7B89:~/Clanlord$ snap remove OpenJDK

snap "OpenJDK" is not installed