There are different types of Java that can be installed, such as Oracle Java and OpenJDK.
Download Oracle Java.
Move the jre-<version>-linux.rpm file to the /tmp folder, and then install the RPM. This will install Java at /usr/bin/java.
~]# rpm -ivh /tmp/jre-<version>-linux.rpm
Create the /usr/lib/jvm directory if it does not already exist.
~]# mkdir /usr/lib/jvm
Move the jre-<version>-linux-i586.tar.gz file to the /tmp folder, and then extract the gzip compressed tar archive to the /usr/lib/jvm.
~]# tar -zxf /tmp/jre-<version>-linux-i586.tar.gz -C /usr/lib/jvm
To install version 8 of OpenJDK on a Debian system:
~]# apt-get install openjdk-8-jre
To install version 8 of OpenJDK on a Red Hat system:
~]# yum install java-1.8.0-openjdk
This will install Java to /usr/lib/jvm/java-<version>/jre/bin/java.
It is also noteworthy that there are different types of OpenJDK that can be installed, such as the developer version of OpenJDK, and the debugging version. Typically, you will just install the OpenJDK Runtime Enviroment. However, if you need another version for some reason, the other versions can also easily be installed using yum or apt-get.
~]# yum search 1.7.0-openjdk ================================================================= java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without audio and video support java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
The JAVA_HOME variable will need to be set for applications that use Java, such as Tomcat. JAVA_HOME is the path to the Java directory that contains the bin folder. For example, if you installed OpenJDK, JAVA_HOME will be /usr/lib/jvm/java-<version>/jre.
It is best to set the JAVA_HOME variable is the users .bash_profile file. After setting JAVA_HOME, the java -version command will dispaly the version of Java being used.
~]# java -version java version "1.8.0_151" Java(TM) SE Runtime Environment (build 1.8.0_151-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)