How-To Install and configure Oracle JDK 1.8 on RHEL/CentOS

Document ID : KB000009887
Last Modified Date : 14/02/2018
Show Technical Document Details
Introduction:

Use of Oracle Java VM 8 is highly recommended for some products, such as Apache Cassandra. In this article, I'll provide detailed instructions on how to download and install JDK 1.8 on RHEL/CentOS.

Background:

There are different JVM implementations available apart from popular Oracle's JVM. Those implementations differ in aspects such as JIT, structure of Java heap, garbage collection and support for monitoring and management. For other software products reliant on the JVM in use, usually manufacturers indicate their preference for the JVM in use, if that makes a difference. For example, Apache highly recommends the use of Oracle Java VM with Cassandra.

Environment:
I have used CentOS Linux release 7.2.1511 (Core) as the OS in this article.
Instructions:

You can either download Oracle JVM by using CA's account from Oracle website to your computer and upload it to the target computer using FTP etc., or use wget to put it there directly. I have used the second method in here:

$cd /tmp

$wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-x64.tar.gz"

 

Now extract the contents of the archive:

$tar -zxf jdk-8u101-linux-x64.tar.gz

 

You should now move it to a proper folder:

$sudo mv jdk1.8.0_101/ /opt/

 

Next, use command update-alternatives to tell system where java and its executables are installed:

$sudo alternatives --install /usr/bin/java java /opt/jdk1.8.0_101/bin/java 2

$sudo alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_101/bin/jar 2

$sudo alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_101/bin/javac 2

$sudo alternatives --install /usr/bin/javaws javaws /opt/jdk1.8.0_101/bin/javaws 2

 

Then confirm that correct alternatives are in play:

$sudo update-alternatives --config java

$sudo update-alternatives --config jar

$sudo update-alternatives --config javac

$sudo update-alternatives --config javaws

 

To setup Java environment variables, add the following lines to /etc/profile.d/java.sh using vi or cat:

export JAVA_HOME=/opt/jdk1.8.0_101

export JRE_HOME=/opt/jdk1.8.0_101/jre

export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

 

You should now reboot the node, so everything is updated:

$sudo reboot

 

Log back in and and confirm that everything is set properly:

$java -version

$echo $JAVA_HOME$'\n'$JRE_HOME$'\n'$PATH

Additional Information:

References:

http://www.tecmint.com/install-java-jdk-jre-in-linux/

https://www.digitalocean.com/community/tutorials/how-to-install-cassandra-and-run-a-single-node-cluster-on-a-ubuntu-vps