Problem to set JAVA_HOME

You can select java version using update-alternatives command.

Run below command in terminal.

sudo update-alternatives --config java

And type selection number that you want to use.

Like this:

selecting java version

Caution: The above description is the procedures for changing a default version. It is not an answer of this question, but should help you set the JAVA home


Ubuntu uses the update-alternatives system to manage which installation of the Java JDK or JRE should be used. This allows you to have multiple versions of Java installed, but still control which one is used by default.

This is why which java doesn't show the version you installed; /usr/bin/java is just a symlink. If you run ls -l /usr/bin/java you'll see something like:

lrwxrwxrwx 1 root root 22 Jul  4  2013 /usr/bin/java -> /etc/alternatives/java

and if you follow the trail by running ls -l /etc/alternatives/java you'll see something like:

lrwxrwxrwx 1 root root 39 Jul 15  2013 /etc/alternatives/java -> /usr/lib/jvm/java-7-oracle/jre/bin/java

but the exact path will depend on which version you have selected.

You can select which version of Java you want to run using this command:

sudo update-alternatives --config java

Your path contains bin/java twice because you have configured $JAVA_HOME incorrectly. $JAVA_HOME should point at the root directory for your Java installation; in your case, /usr/lib/jvm/java-7-openjdk-i386/. You were pointing it at the java binary itself.

You should not need to add $JAVA_HOME to your $PATH unless you are installing Java manually and not using update-alternatives, because /usr/bin is already in your $PATH.


You have incorrectly set your JAVA_HOME variable in your ~/.bash_profile file. Change your JAVA_HOME variable to:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/

and then do source ~/.bash_profile

This should resolve your issue.