I am installing Apache Solr on Linux Debian (Squeeze). I have been instructed to install sun-java jdk 1st. Then am told that I should use the command sudo update-alter
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.
If you want to switch the jdk on a regular basis (or update to a new one once it is released), it's very conveniant to use sdkman.
You can additional tools like maven with sdkman, too.