Ubuntu – How to remove all version of java completely from Linux system

java

I use Ubuntu 14.04 LTS, 64-bit.
In attempt to run some 32-bit programs, I had to install java version 6. Java version 7 was already present.
I used update-alteratives to switch between them.
Somehow I messed up completely and want to remove all contents of both versions of java and re-install.
I used apt-get remove but I think some parts of java are being left over.

Question :
How do I remove java from scratch from my ubuntu system ?

Any help is highly appreciated. TIA.

Best Answer

The following solution removes all Java installations (OpenJDK and Oracle Java), installed via the Package Manager


  1. Check the output of the commands below and check twice if it's ok to remove

    dpkg --get-selections | awk '/oracle-java/ && /installer/ {print "sudo apt-get purge "$1}' 
    dpkg --get-selections | awk '/openjdk/ {print "sudo apt-get -y purge "$1}' 
    
  2. After that purge OpenJDK and Oracle Java via

    dpkg --get-selections | awk '/oracle-java/ && /installer/ {system("sudo apt-get purge "$1)}'
    dpkg --get-selections | awk '/openjdk/ {system("sudo apt-get -y purge "$1)}'
    
Related Question