JAVA_HOME and PATH are set but java -version still shows the old one

user517491 picture user517491 · Jan 2, 2013 · Viewed 210.1k times · Source

I am using Linux Mint Cinnamon 14. I have set the $JAVA_HOME and $PATH environment variables in ~/.profile as follows:

export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=/home/aqeel/development/jdk/jdk1.6.0_35/bin:$PATH

I then did source ~/.profile to make the proper changes.

When I execute java -version command to check the active java version, it shows the default (already installed open-jdk) java version. How can I override the default open-jdk with the one I downloaded?

UPDATE:

which java says /usr/bin/java

$JAVA_HOME/bin/java -version says 'Permission Denied'

sudo $JAVA_HOME/bin/java -version (asks for password, then) says Command not found

but cd $JAVA_HOME/bin, and ls shows that it is right directory.

Answer

Anders R. Bystrup picture Anders R. Bystrup · Jan 2, 2013

While it looks like your setup is correct, there are a few things to check:

  1. The output of env - specifically PATH.
  2. command -v java tells you what?
  3. Is there a java executable in $JAVA_HOME\bin and does it have the execute bit set? If not chmod a+x java it.

I trust you have source'd your .profile after adding/changing the JAVA_HOME and PATH?

Also, you can help yourself in future maintenance of your JDK installation by writing this instead:

export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=$JAVA_HOME/bin:$PATH

Then you only need to update one env variable when you setup the JDK installation.

Finally, you may need to run hash -r to clear the Bash program cache. Other shells may need a similar command.

Cheers,