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.

Answer from Eric Carvalho on askubuntu.com
🌐
Oracle
java.com › en › download › help › linux_uninstall.html
How do I uninstall Java for Linux?
Java version(s): 7.0, 8.0 · The uninstall process consists of: Java Plug-in Uninstall · Java Uninstall · RPM Uninstall · Self extracting Uninstall · If you are going to reinstall Java, you don't need to uninstall Java Plug-in. Just use the -f option for ln when creating a new symbolic link.
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.)

Discussions

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
Can't remove java in Ubuntu 16.04 - Stack Overflow
I want to install java 8 in my virtualbox ubuntu16.04, but whenever I check version using -version, it shows · > java -version java version "1.7.0_05" Java(TM) SE Runtime Environment (build 1.7.0_05-b06) Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode) To uninstall and reinstall ... 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
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
October 2, 2021
🌐
Linux Hint
linuxhint.com › uninstall-java-ubuntu
How to uninstall Java from Ubuntu – Linux Hint
The difference between “Open JDK” and “Oracle Java” is that the former is open-source, whereas the latter is license-based. Oracle Java is much better when it comes to performance and stability. Before uninstalling java from your PC, it is essential to know which version of java you have got.
🌐
Explainjava
explainjava.com › uninstall-java-ubuntu
How to Uninstall Java on Ubuntu – Java Programming Tutorials
November 22, 2020 - There are 2 options depending on the type of JDK (OpenJDK or Oracle JDK) how to uninstall Java in Ubuntu. Check installed Oracle JDK packages: grep oracle-java · Remove Java 8: sudo apt-get remove --purge oracle-java8-installer · Removing Java 9: sudo apt-get remove --purge oracle-java9-installer ...
🌐
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 - For those who have installed Oracle JDK, there are two ways to uninstall Java. You can double-click the DEB package file to open Snap Store and then click the Remove button to uninstall the package.
🌐
Learn Ubuntu
learnubuntu.com › uninstall-java
Uninstall Java From Ubuntu
April 11, 2023 - If you installed a specific version of JRE on your Ubuntu machine, you can use the similar command syntax as above to remove JRE: ... This section is useful for those who used the .deb file to install Java in Ubuntu.
Find elsewhere
🌐
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

🌐
UbuntuMint
ubuntumint.com › home › how to completely uninstall java on ubuntu
How to Completely Uninstall Java on Ubuntu
July 24, 2023 - Removing Java from Ubuntu is simple and can be done using the apt remove command followed by the package name with wild card character.
🌐
Quora
quora.com › How-do-I-remove-JDK-from-Ubuntu
How to remove JDK from Ubuntu - Quora
Commands and package names reflect ... by Ubuntu release. ... Self taught programer (old BASIC and ASM), now back-end dev · Author has 973 answers and 2M answer views · 4y · You can either look for it in the Software Manager and uninstall, or open a terminal windows and type sudo apt remove java<version>-sdk . Where, of course, version is the number (8, 9, 10, 11, ...
🌐
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: [To uninstall Openjdk 7] $ sudo apt-get purge openjdk-7-* [To remove Oracle Java 7] $ sudo apt-get remove oracle-java7-installer [To Uninstall Oracle Java 8] $ ...
🌐
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 - – Novice Stuffs ... When i executed the following command in my Ubuntu box which had openjdk- sudo apt-get purge –auto-remove openjdk* It asked me this will free up 5,084 MB of space.
🌐
GitHub
gist.github.com › lovato › 7063928
Wipe out Java from Ubuntu, and then fresh install it back. · GitHub
Wipe out Java from Ubuntu, and then fresh install it back. - java-reinstall.sh
🌐
Oracle
java.com › en › uninstall › uninstall_instructions.html
Uninstall instructions for Java
The Add/Remove control panel displays a list of software on your system, including any Java software products that are on your computer. Select any that you want to uninstall by clicking on it, and then click the Remove button.