Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to set JAVA_HOME in Ubuntu OS. I have copied jdk 1.7 in /usr/lib/jvm and set JAVA_HOME in /etc/profile file.

Contents of /usr/lib/jvm folder are as follows :

shekhar@ubuntu:~$ ls /usr/lib/jvm/
default-java        java-1.6.0-openjdk       java-6-openjdk         java-6-openjdk-i386  jdk1.7.0_01
java-1.5.0-gcj-4.6  java-1.6.0-openjdk-i386  java-6-openjdk-common  java-7-openjdk-i386

and last few lines of /etc/profile file are as follows :

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_01
export PATH=$PATH:$JAVA_HOME/bin

After finishing all this when I run java -version command I get following output :

shekhar@ubuntu:~$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.4) (6b24-1.11.4-1ubuntu0.12.04.1)
OpenJDK Server VM (build 20.0-b12, mixed mode)

and when I run ls -lah command I get following output :

shekhar@ubuntu:~$ ls -lah /usr/bin/java
lrwxrwxrwx 1 root root 22 Sep 29 09:58 /usr/bin/java -> /etc/alternatives/java
shekhar@ubuntu:~$ ls -lah /etc/alternatives/java
lrwxrwxrwx 1 root root 45 Sep 29 09:58 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java

Can anyone please tell me which thing I am missing? Why Ubuntu is still pointing to open jdk and not to my jdk 7?

PS : I have seen this similar question and its answers but that question is related to Windows OS and not for Ubuntu so I am reposting this similar question for Ubuntu.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

You set the JAVA_HOME environment variable, and then you used that to set your PATH. However, the path you set also consists of the existing path. Essentially, you just added something else to your existing path.

The path to your JDK1.7 is added at the end of the path. When you type 'java --version' on the command line, the system searches through the path from beginning to end until it finds a path that has the command 'java'. Therefore, what you're seeing is the version output from one of your other Java versions.

What I typically do on Ubuntu is look at my path:

echo $PATH

and then look for possible JVM paths near the beginning. At that point, you'd have several options to fix this:

  1. Create a symlink pointing the system to your new Java path.

  2. Remove the old Java version and remove it from your path.

I'd opt for option 2. It's less confusing to just get rid of what you don't need.

share|improve this answer
Hi, You were right. Somehow there's other open jdk installed which was coming before my jdk 1.7. I just re arranged PATH variable so as to bring my jdk first in PATH. Now its working fine. Thanks... –  Shekhar Sep 29 '12 at 14:44

I personally was facing exactly the same kind of problem on a fresh Ubuntu 12.04 install. All I had to do is to uninstall a specific package using the following command:

sudo apt-get remove openjdk-6-jre-headless

This removed the link in the /etc/alternatives and updated it to the installed java 1.7

Just wanted to share as this completes point 2 in jmort253's answer.

share|improve this answer

I had the same problem, and the answer is hidden in the PATH:

running "$ env | grep java" shows:


but running "java -version" still show:

java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

I figured out that my PATH has "/usr/bin" before "/java/jdk1.6.0_14/bin" and doing "ll /usr/bin | grep java" i got:

lrwxrwxrwx 1 root root 39 Jul 31 08:29 /etc/alternatives/java -> /usr/lib/jvm/java-7-oracle/jre/bin/java*

I changed the simbolic link to the correct one and problem solved. You may also change the order at path:


export PATH=$PATH:$JAVA_HOME/bin


export PATH=$JAVA_HOME/bin:$PATH
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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