1

When I run java -version in my terminal I get:

user@ubuntu:~$ java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

I need to change my java to 5. I have downloaded jdk5 which is located here:

/home/user/tools/jdk1.5.0_22

First I have tried to add the following to my ~/.bashrc file:

JAVA_HOME=/home/user/tools/jdk1.5.0_22
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH 

I have then restarted my terminal but I still get:

user@ubuntu:~$ java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

I have then tried to add JAVA_HOME to /etc/environment :

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

JAVA_HOME=/home/user/tools/jdk1.5.0_22

After restarting the terminal (close and open a new one) java still points to jdk 7:

user@ubuntu:~$ java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

But it seems that the JAVA_HOME is set:

user@ubuntu:~$ echo $JAVA_HOME
/home/user/tools/jdk1.5.0_22

How do I change the version of java that I use?

  • What do you mean by "restarting the terminal"? – Joseph R. Oct 17 '13 at 18:54
3

The first java executable found in your PATH is /usr/bin/java, which is probably a link to /etc/alternatives/java which is probably a link to /usr/lib/jvm/java-7-oracle/jre/bin/java.

You can try setting your PATH to have your new java location in the beginning. You did the opposite by adding it in the end. You should have tried the following:

export PATH=/home/user/tools/jdk1.5.0_22/bin:$PATH

In combination with JAVA_HOME you should be OK, but another more debian-ish (or ubuntu-ish) way is to use the update-alternatives utility.

sudo update-alternatives --install /usr/bin/java java /home/user/tools/jdk1.5.0_22/bin/java 100
sudo update-alternatives --set java /home/user/tools/jdk1.5.0_22/bin/java

But you need to do this with all executable files you intent to use from that installation.

For more details see https://askubuntu.com/q/159575/11831

  • Doing this: PATH=$JAVA_HOME/bin:$PATH in my .bashrc instead of PATH=$PATH:$JAVA_HOME/bin fixed the problem. – u123 Oct 17 '13 at 19:29
0

You may want to check into the whereis command as well as alternatives. Check if there is a symlink in /etc/alternatives/java that points to IcedTea rather than your desired java executable. You may want to check the alternatives command to install a new alternative and set it as desired.

Edit: Link to the RHEL documentation as an example: https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_SOA_Platform/4.3/html/Getting_Started_Guide/appe-install_jdk_rhel.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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