Which of these Paths should I use as the value of JAVA_HOME?

I am running Ubuntu 16.04. I have downloaded JDK 7.0 from Oracle website and untar'ed and put it in a folder /opt/JDK/, such that the final install directory is /opt/JDK/jdk1.7.0_80 Then I executed the following commands given in this SO answer:

update-alternatives --install /usr/bin/java java /opt/jdk1.8.0/bin/java 1
update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0/bin/javac 1
update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.8.0/jre/lib/amd64/libnpjp2.so 1
update-alternatives --set java /opt/jdk1.8.0/bin/java
update-alternatives --set javac /opt/jdk1.8.0/bin/javac
update-alternatives --set mozilla-javaplugin.so /opt/jdk1.8.0/jre/lib/amd64/libnpjp2.so

I want to set the JAVA_HOME environment variable. I know how to do it using /etc/environment. The confusion is which path to use.

Should I use /usr/bin/java?

Or should I use /opt/JDK/jdk1.7.0_80?

Or should I use /opt/JDK/jdk1.7.0_80/bin?

The output of update-alternatives --config java is:

There is 1 choice for the alternative java (providing /usr/bin/java). Selection Path Priority Status
------------------------------------------------------------ 0 /opt/JDK/jdk1.7.0_80/bin/java 1 auto mode
* 1 /opt/JDK/jdk1.7.0_80/bin/java 1 manual mode
Press <enter> to keep the current choice[*], or type selection number:

1 Answer

As you can see two alternatives are identical, so you can use both of them. Simply you can use following command to set JAVA_HOME:

JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

The command update-alternatives --config java is used when you have different JAVA installed on your machine. For example Mine is as follow:

There are 2 choices for the alternative java (providing /usr/bin/java).

* 0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 auto mode 1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like