The update-alternatives is used to handle situations where multiple applications that accomplish the same task are installed on the system, but we would like to set a default on which one to be used…..

I moved the JDK from another system into /usr/lib/jvm/java-8-oracle

If I just try to compile with javac or run java or javaws on the command, I will get “command not found” as the java binaries in /usr/lib/jvm/java-8-oracle/bin are not in my exported PATH.

I could add to my PATH in .bashrc the path to /usr/lib/jvm/java-8-oracle/bin. That would solve the problem of running these commands from any directory on the command line but it would not work for another user on the system.

So, add the java, javac and javaws or any other commands as defaults.

Add a new alternative for “java”, “javac” and “javaws”.

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-8-oracle/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-8-oracle/bin/javac 1
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/java-8-oracle/bin/javaws 1

You can now list all alternatives for the “java” name for example and set which one will be the default by using the –config option:

sudo update-alternatives --config java

Default java commands for manually installed JDK on Debian based distros

Leave a Reply

Your email address will not be published. Required fields are marked *

*