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
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.)

🌐
Oracle
java.com › en › download › help › linux_uninstall.html
How do I uninstall Java for Linux?
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. 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.
Discussions

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
how to uninstall java
Have you tried sudo yum remove jok-20-headless? More on reddit.com
🌐 r/linuxquestions
2
1
May 24, 2023
Uninstall Java 18 and install java 8 or 11 with FX.
I'd suggest not to uninstall java18, but download java8 from oracle, unpack it somewhere and create a simple launch script like: #!/bin/bash ~/soft/jdk8/bin/java -jar ~/soft/sqldeveloper/sqldeveloper.jar More on reddit.com
🌐 r/Ubuntu
1
1
April 9, 2022
🌐
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

🌐
Linux Hint
linuxhint.com › uninstall-java-ubuntu
How to uninstall Java from Ubuntu – Linux Hint
In the above discussion, we learned that there are multiple versions of java; you can have all of them on your PC at a time and conveniently switch them. Various approaches can be used to delete java from ubuntu.
🌐
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.
🌐
Learn Ubuntu
learnubuntu.com › uninstall-java
Uninstall Java From Ubuntu
April 11, 2023 - Once you find the package name, you can use the traditional apt remove command to remove the package: ... And that's it! In case you want to install Java again, we have a detailed guide for that purpose covering almost every aspect of installing ...
Find elsewhere
🌐
Linux Today
linuxtoday.com › home › developer
How to Completely Uninstall Java on Ubuntu
June 16, 2023 - In this step-by-step guide, we will guide you through the process of uninstalling Java from your Ubuntu system.
🌐
Quora
quora.com › How-do-I-remove-JDK-from-Ubuntu
How to remove JDK from Ubuntu - Quora
Check active java executables: java -version javac -version readlink -f $(which java) ... To remove the JDK from Ubuntu, identify which Java packages are installed, then uninstall the appropriate packages and clean up alternatives and residual files.
🌐
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 - Pingback: How To Install Java On Linux ? – 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.
🌐
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 - Alternatively, you can remove the package using your system terminal: Get the JDK package name using dpkg and grep. ... Then, uninstall the package using APT. Remember to replace the package name with the output of the previous command.
🌐
YouTube
youtube.com › pace edu.
How to uninstall java on ubuntu - YouTube
uninstall java ubuntuHow to Uninstall Java on Ubuntuuninstall java 8 ubuntuuninstall java 11 ubuntuuninstall openjdk-11 ubuntuuninstall java linuxuninstall j...
Published   July 7, 2021
Views   7K
🌐
Local Host
locall.host › home › uninstall › mastering the removal process: a comprehensive guide to uninstalling java on ubuntu systems
Mastering the Removal Process: A Comprehensive Guide to Uninstalling Java on Ubuntu Systems
August 10, 2023 - For example, to remove Oracle Java 8: “` sudo update-alternatives –remove “java” “/usr/lib/jvm/java-8-oracle/jre/bin/java” “` 3. Finally, delete the Oracle Java folder manually: “` sudo rm -rf /usr/lib/jvm/java-8-oracle “` In summary, the main difference between uninstalling OpenJDK and Oracle Java lies in the tools and commands used (apt-get for OpenJDK and update-alternatives for Oracle Java) and the requirement to manually delete the Oracle Java folder. Uninstalling Java on Ubuntu can sometimes lead to common issues.
🌐
Linux Hint
linuxhint.com › uninstall-java-ubuntu-2204
How to Uninstall Java from Ubuntu 22.04 – Linux Hint
To uninstall the Java package from Ubuntu 22.04, we will run the command “sudo rm -r /usr/lib/jvm ” after confirming the directory of jvm. In this write-up, the method of uninstalling Ubuntu has been explained in detail.
🌐
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
🌐
Code2care
code2care.org › home › q › how to remove or uninstall java from ubuntu using apt-get
How to remove or uninstall Java from Ubuntu using apt-get | Code2care
January 26, 2026 - If you want to remove the Java package from Ubuntu you can make use of the apt-get remove command followed by package name,
🌐
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 - In this tutorial, we’ve walked through the steps to manage Java versions on Linux by removing outdated versions, installing the latest updates, and properly configuring the system.
🌐
Medium
hirosht.medium.com › uninstall-openjdk-in-ubuntu-bb18e66f5bda
Uninstall OpenJDK in Ubuntu. Though the Ubuntu environments comes… | by Hirosh Tharaka | Medium
June 6, 2019 - Remove OpenJDK along with dependencies and it’s configuration files, execute the following command on terminal: $ sudo apt-get purge --auto-remove openjdk* This is how you can uninstall OpenJDK.
🌐
Akbarahmed
akbarahmed.com › 2012 › 06 › 24 › uninstall-java-from-ubuntu-linux
Uninstall Java from Ubuntu Linux | AkbarAhmed.com
June 24, 2012 - sudo update-alternatives --remove "javaws" \ "/usr/lib/jvm/jdk1.7.0_04/bin/javaws" Let’s quickly verify that the commands above remove the symlinks. ... You should no longer see 1.7.0 u04 for the version of any of the above commands. IMPORTANT WARNING You must type the next 2 commands perfectly to avoid permanently destroying your system. If you do this wrong, you could delete important system files, including those that are required by Ubuntu.