uninstall java in linux

How to Uninstall Java in Ubuntu

Java is a popular programming language used by software developers and web developers around the world. It is used to create websites, applications and mobile apps. Sometimes you may need to uninstall Java from your system, for one reason or the other. Here are the steps to uninstall Java in Ubuntu.


How to Uninstall Java in Ubuntu

Here are the steps to uninstall Java in Ubuntu.


1. Remove Java Packages

Open terminal and run the following command to uninstall Java related packages in Ubuntu.

$ 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. Remove Config files

Next we will remove the config files. Please note, it will also remove libsgutils2-2 and virtualbox config files also.

$ dpkg -l | grep ^rc | awk '{print($2)}' | xargs sudo apt-get -y purge


3. Remove Java config & cache directory

Then we remove Java config & cache directory.

$ sudo bash -c 'ls -d /home/*/.java' | xargs sudo rm -rf


4. Remove JVMs

Next, we will run the following command to remove any manually installed JVMs.

$ sudo rm -rf /usr/lib/jvm/*


5. Remove Java entries

Then remove all Java entries from alternatives. The following command will loop through all the tools in alternatives and delete any java entries.

$ 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 Java directories

Finally, search for any remaining Java folders.

$ sudo updatedb
$ sudo locate -b '\pack200'

If the output contains something like /path/to/jre1.6.0_34/bin/pack200 use the rm command to delete the parent folder of bin subfolder.

$ sudo rm -rf /path/to/jre1.6.0_34

In this article, we have learnt how to completely uninstall Java from Linux.

Also read:

How to Format USB Drives in Linux
How to Convert Epoch to Date in Linux
How to View Linux Log Files
How to Convert Files to UTF-8 in Linux
How to Set or Change Hostname in RHEL/CentOS

Leave a Reply

Your email address will not be published.