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
Maybe, just the guide is outdated.
After you install the rpm, you can check:
to see if you can see the new version is controlled by alternative, if not you need to "--install" them; otherwise, I think you can just skip "--install" part.
To get a different version of java JRE/JDK as default in your OS:
Example in my case was:
Then run a config to select the alternative java version:
Choose 1,2 or the option you desire
Then check the changes by doing:
These "alternatives" scripts and similar tools just symlink binaries of desired JDK version to the directories they are expected to be. It's done for all commands that should be available on your command line.
Definition of "all" depends on your distro.
When you install JDK on Linux, it it 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 variablePATH
. Commands typed on the terminal needs to be from the locations specified in thePATH
variable. In cases whenJDK\bin
does not get added, the user would need to configure it manually as mentioned in Installing the JDK Softwarealternatives
command is being used to create a symbolic link. Here, it is being directed to use the command to add the tools likejavac
,javaw
to/usr/bin
which exists in thePATH
variable by default.If( you could execute
java -version
outside ofJDK/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 thealternatives
command.}java
,javaws
,javac
, andjar
are all different executables used by the JDK. When you runalternatives --config java
you are only configuring which version of thejava
executable you wish to run. However, the JDK includes, for example, thejavac
compiler. You need to configure which version of the compiler you wish to use as well.The alternatives command is, in a nutshell, used to maintain a lookup for symbolic (or sym) links. Before you can choose which version of
java
you want to run with the--configure
option, you must first register the actual path to the executable with the--install
option.alternatives --install
is not installing any software. It is merely registering some paths and aliases with thealternatives
framework. (Note:alternatives
is not using thealias
command. I mean "aliases" in the traditional, literal sense.)You should also understand what the
rpm
command does. Really, it is only dropping down a set of binaries into a particular directory. This directory may be long and tedious to explicitly specify:/some/path/to/lib/jvm/java-1.x.x-etc-etc-x86/jre/bin/java
. You don't want to specify this every time you want to runjava
. Instead, we set up some sym links.You might also want to read up on how the
PATH
works in linux.It may become clearer if you try tracing through the setup for your machine. Here is what I ran:
For Ubuntu use
update-alternatives