How to completely uninstall Java?
1) Remove all the Java related packages
sudo apt-get update
apt-cache search java | awk '{print($1)}' | grep -E -e(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^java-common' | xargs sudo apt-get -y remove
sudo apt-get -y autoremove
2) Purge config files
After removing all the packages you need to purge all the config files. For that run the following command:
dpkg -l | grep
^rc ^rc | awk '{print($2)}' | xargs sudo apt-get -y purge
Remove cache directory
After purging the config files we need to remove3) Remove Java config and cache directory
from your system. Run the following command to remove the cache directory:
sudo bash -c 'ls -d /home/*/.java' | xargs sudo rm -rf
4) Remove manually installed
JVM'sIf you have installed any other JVM's then this is the time to remove them. Run the following commandJVMs:
sudo rm -rf /usr/lib/jvm/*
5) Remove
all leftoverJava entries
After uninstalling all the java components from your system some java entries might still be left in your system. To get rid of them run the following command, if there is still any, from the alternatives:
Remove java directories from system
This is the final step in removing Java from your system. After uninstalling the java packages the java directories might still be there in your system. To remove them you need to first find if there are any left. Use the following commands to find any leftover directories:
sudo updatedb sudo locate -b '\pack200' |
If after running the above script you get any output similar to 'jre1.5/bin/pack200' then run the following command (replace jre1.5 with the directory name that you got in the output at the terminal) to remove the leftover java directory:
sudo rm -rf /path/to/jre1.5for 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 done
6) Search for possible remaining Java directories:
sudo updatedb sudo locate -b '\pack200'
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