How to use the command update-alternatives --config java
Solution 1:
You will notice a big change when selecting options if you type in "java -version" after doing so. So if you run update-alternatives --config java
and select option 3
, you will be using the Sun implementation.
Also, with regards to auto
vs manual mode
, making a selection should take it out of auto mode
per this page stating:
When using the
--config
option, alternatives will list all of the choices for the link group of which given name is the master link. You will then be prompted for which of the choices to use for the link group. Once you make a change, the link group will no longer be inauto mode
. You will need to use the--auto
option in order to return to the automatic state.
And I believe auto mode
is set when you install the first/only JRE/JDK.
Solution 2:
Assuming one has installed a JDK in /opt/java/jdk1.8.0_144
then:
-
Install the alternative for javac
$ sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.8.0_144/bin/javac 1
-
Check / update the alternatives config:
$ sudo update-alternatives --config javac
If there is only a single alternative for javac
you will get a message saying so, otherwise select the option for the new JDK.
To check everything is setup correctly then:
$ which javac
/usr/bin/javac
$ ls -l /usr/bin/javac
lrwxrwxrwx 1 root root 23 Sep 4 17:10 /usr/bin/javac -> /etc/alternatives/javac
$ ls -l /etc/alternatives/javac
lrwxrwxrwx 1 root root 32 Sep 4 17:10 /etc/alternatives/javac -> /opt/java/jdk1.8.0_144/bin/javac
And finally
$ javac -version
javac 1.8.0_144
Repeat for java, keytool, jar, etc as needed.