Java 7 on RHEL with Alternatives

August 5, 2015

To install Java on RHEL, download it and unpack.

You can then use the alternatives command to add it as a new option for java, and switch to it:

[root@linux07 ~]# alternatives --install /usr/bin/java java /apps/jdk/jdk1.7.0_67/bin/java 3
[root@linux07 ~]# alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
*+ 2           /usr/java/jdk1.6.0_45/jre/bin/java
   3           /apps/jdk/jdk1.7.0_67/bin/java

Enter to keep the current selection[+], or type selection number: 3
[root@linux07 ~]# java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
[root@linux07 ~]#