When and Why run alternatives --install java jar javac javaws on installing jdk in linux

Charu Khurana picture Charu Khurana · Sep 23, 2015 · Viewed 15.9k times · Source

To install java in linux (I used CentOS, RHEL is same too), I used this command

rpm -Uvh /path/to/binary/jdk-7u55-linux-x64.rpm

and verified java

java -version

Looking at a tutorial, it says to run following 4 commands, not sure why

## java ##
alternatives --install /usr/bin/java java /usr/java/latest/jre/bin/java 200000
## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/latest/jre/bin/javaws 200000

## Install javac only
alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 200000
## jar ##
alternatives --install /usr/bin/jar jar /usr/java/latest/bin/jar 200000

I know if there are multiple versions of java installed, you can select version to use from

alternatives --config java

then why to run alternative --install separately for each executable.

I've seen this question but doesn't get my answer

Answer

James Jithin picture James Jithin · Sep 25, 2015

When you install JDK on Linux, what gets installed depends on the type of package, version and distribution. You can refer to the following links for information about the installation location on linux:

JDK Installation for Linux Platforms - Version 8

JDK Installation for Linux Platforms - Version 7

Once you install JDK, the bin folder containing tools might not get added to the environment variable PATH. Commands typed on the terminal needs to be from the locations specified in the PATH variable. In cases when JDK\bin does not get added, the user would need to configure it manually as mentioned in Installing the JDK Software

alternatives command is being used to create a symbolic link. Here, it is being directed to use the command to add the tools like javac, javaw to /usr/bin which exists in the PATH variable by default.

If( you could execute java -version outside of JDK/bin && not by specifying the complete path && if the version and bundle prints to be as that of package you installed ){ you need not run the alternatives command.}