Default JAVA, $JAVA_HOME vs sudo update-alternatives --config java

update-java-alternatives is a program to update alternatives for jre/jdk installations.
update-alternatives is a symbolic link management system for linux (I'm sure there is little news here).


sudo update-alternatives --config java
Configures the default for the program "java". That's the Java VM.
sudo update-alternatives --config javac
Configures the default Java compiler.
Then, why doesn't the executed version change when you do the update-alternativescommand ? I guess it's because of the order the executables are found in $PATH. Since you added a directory to the PATH environment variable, there are now two possible java executables : one in /usr/bin and the other in /opt/jdk1.8.0_9, but only the first one found will be taken into account when you'll type java commands.
And because you set
PATH=$JAVA_HOME/bin:$PATH
The first one will be found in $JAVA_HOME/bin aka /opt/jdk1.8.0_91 . Because you made /opt/jdk1.8.0_9 appear before /usr/bin which is defined by default in the the PATH variable. You can check it by typing in a terminal
$echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/path/to/my/java/installation/1.x/bin
You can see that my java/bin dir is located after the others defined in the PATH.
To correct this, you just have to concatenate $JAVA_HOME/bin after $PATH, like this :
PATH=$PATH:$JAVA_HOME/bin
This way you will be able to choose the default java executable from alternatives and the java exe found in $JAVA_HOME/bin will be discarded. But to be consistent, in most cases you should choose the same java exe as in $JAVA_HOME/bin.

Comments

Popular posts from this blog

HAproxy logging

teamcity Automatic Agent Start under Linux

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all