Completely uninstall and reinstall OpenJDK

Solution 1:

You cannot remove OpenJDK 7 because it is not installed. If you are trying to remove OpenJDK 6, try sudo apt-get remove openjdk-6-jdk, or sudo apt-get remove default-jdk.

apt-cache search only shows you available packages, not the packages you have installed. For that, try sudo dpkg --list; sudo dpkg --list | grep -i jdk will show you any JDK-related packages installed on your system.

Solution 2:

Run this command, which lets you choose which Java installation to make the default:

sudo update-alternatives --config java

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java         1         manual mode

Solution 3:

Recently, I tried to reinstall Java completely. This may help you to remove it:

sudo apt-get remove openjdk*
sudo apt-get clean

Then, if you want, install Java:

sudo apt-get install openjdk-8-jdk

Following these steps helped me to solve my problem.