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.

  • Thanks for the reply @learningloop. I will try this and get back. Meanwhile, it would be great if you could tell me where and what components are installed when we install java. This would make my task more precised of removing each and every component incase 'purge' and 'remove' can't succeed 100%.
    – v1h5
    Jul 27, 2015 at 13:32
  • 1
    Possible duplicate of How to completely uninstall Java?
    – amc
    Oct 21, 2016 at 0:03

3 Answers 3


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)}'
  • A very good one!
    – Pilot6
    Jul 27, 2015 at 14:23
  • Perfect. Precisely the best answer I was looking for. Thank you so much A.B
    – v1h5
    Jul 27, 2015 at 14:46
  • dpkg --get-selections | awk '/openjdk/ {system("sudo apt-get purge -y "$1)}' <--this command re-installs Java. Is it what it should do ?
    – v1h5
    Jul 27, 2015 at 14:48
  • No, the first both commands gives you an overview, the second both commands removes Java.
    – A.B.
    Jul 27, 2015 at 14:51
  • I don't know why but after executing second command, I start seeing the installation screen again. :-\
    – v1h5
    Jul 27, 2015 at 17:48

use apt-get purge to remove anything including configs and alike.

If the problems persist, you can always use find -name '*java*' or to find any java remainders. Note that you might also need to search for e.g. jvm (java virtual machine) and that find will allow deleting, but use this command with care.

Alternatively you can always force a reinstall: apt-get install --reinstall package-name

This could cure the problems with your java.


I'm not fully sure what you understand by "some parts of java are remaining on my system", but running these 2 commands will tell you what's installed relatively to java and the openjdk VM.

dpkg --get-selections | grep java
dpkg --get-selections | grep jdk

Lots of "java"-tagged packages are actually libraries and bindings, you probably don't care much about those. The core of the java is in the commons i think.

Also, maybe your problem comes from leftover config files... don't forget to apt-get purge your packages!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.