Engineering Leadership


Hopefully you won’t need these instructions due to a botched install, but there may come a time where you need to uninstall a version of the JDK/JVM.

These instructions are for the Oracle JDK 1.7.0 Update 4 on Ubuntu 12.04 LTS. If you are using a different version of the JDK, then change the version numbers listed below.

I have also included instructions for removing the OpenJDK at the bottom of this post.

Uninstall Java

Let’s check the current setup before we uninstall Java.

sudo update-alternatives --display java

The output from the command will be something like:

java - manual mode
link currently points to /usr/lib/jdk1.7.0_04/bin/java
/usr/lib/jdk1.7.0_04/bin/java - priority 1
/usr/lib/jvm/j2sdk1.6-oracle/jre/bin/java - priority 315
slave java.1.gz: /usr/lib/jvm/j2sdk1.6-oracle/man/man1/java.1.gz
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1051
slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
Current 'best' version is '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java'.

Next, we’ll remove each symlink to a Java binary from the Debian alternatives system. I have split the following commands onto multiple lines to ensure that they display correctly on this page. However, you can remove the \ and then type each command on one line in the terminal.

sudo update-alternatives --remove "java" \
sudo update-alternatives --remove "javac" \
sudo update-alternatives --remove "javaws" \

Let’s quickly verify that the commands above remove the symlinks.

java -version
javac -version
which javaws

You should no longer see 1.7.0 u04 for the version of any of the above commands.

You must type the next 2 commands perfectly to avoid permanently destroying your system. If you do this wrong, you could delete important system files, including those that are required by Ubuntu.

cd /usr/lib/jvm
sudo rm -rf jdk1.7.0_04
sudo update-alternatives --config java

update-alternatives: error: no alternatives for java.

sudo update-alternatives --config javac

update-alternatives: error: no alternatives for javac.

sudo update-alternatives --config javaws

update-alternatives: error: no alternatives for javaws.

sudo vi  /etc/environment

Delete the line with JAVA_HOME

Uninstall OpenJDK (if installed)

First we’ll check which OpenJDK packages are installed.

sudo dpkg --list | grep -i jdk

Next, let’s uninstall OpenJDK related packages. Edit the list of packages below if you have additional or different OpenJDK packages installed.

sudo apt-get purge icedtea-* openjdk-*

Let’s check that all OpenJDK packages have been removed.

sudo dpkg --list | grep -i jdk

9 thoughts on “Uninstall Java from Ubuntu Linux

  1. Tim Brandt says:

    Thank you; so simple!

  2. Kannan says:

    Akbar – Wow, fantastic explanation….very useful and clear step by step instructions. Keep up the good work and thanks for your effort…..!!!!

  3. I am really fascinated by your article here, i have a facebook group of pretty much same category, i was wodering if i can post your stuff there in my facebook group by your permission, ofcourse.

    1. akbarsahmed says:

      Hi, I’d prefer that you link to the post.

  4. Raju says:

    It’s a nice Sequence of steps with good Explanation.
    But still I am Getting java version when i typed “which java”.
    what would be the problem?

    1. akbarsahmed says:

      Please paste the exact command and output here.

  5. eva says:

    Thank you….!

  6. Niaz says:

    I could not run my own installed java version. I have unintalled the java from the system using above commands. Downloaded the jdk from following site and uncompressed to my home directory.

    Now added the path to “PATH” variable in the /etc/environment file like below:

    Added following like to ~/.bashrc file
    export JAVA_HOME=/home/niaz/jdk1.7.0_40/bin/java

    If I run from console the command >java -version
    it outputs like following:

    The program ‘java’ can be found in the following packages:
    * default-jre
    * gcj-4.6-jre-headless
    * openjdk-6-jre-headless
    * gcj-4.5-jre-headless
    * openjdk-7-jre-headless
    Try: sudo apt-get install

    But if I go to my home directory, where java is uncompressed and execute like >./java -version. It outputs the version correctly.

    Could you please tell what is missing to have my own java version on the central point for all programs. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: