Most everything we want to do other than the base functionality of the computer is going to require a Java Development Kit (JDK). Let’s go through the quick and easy install.

1. Download

Find the latest version of the JDK using:

sudo yum list java\*-openjdk.x86_64

Pick the latest one and install both the base and developer version to ensure we’re getting the latest compiler version as well:

sudo yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

2. Configure Java

We need to set the default JDK to use:

sudo /usr/sbin/alternatives --config java

Make sure you have the latest one selected, if not, enter that number:

# There are 2 programs which provide 'java'.
#
#   Selection    Command
# -----------------------------------------------
# *+ 1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/jre/bin/java)
#    2           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.131-2.6.9.0.el7_3.x86_64/jre/bin/java)

3. Configure Javac

Annoyingly, tConfigure the default Java compiler

sudo /usr/sbin/alternatives --config javac

Make sure you have the version that matches your selection for Java:

# There is 1 program that provides 'javac'.
#
#   Selection    Command
# -----------------------------------------------
# *+ 1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/bin/javac)

4. Check

Check your versions:

$ java -version
# openjdk version "1.8.0_131"
# OpenJDK Runtime Environment (build 1.8.0_131-b11)
# OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

$ javac -version
# javac 1.8.0_131

5. Set Environment Vars

Set your JAVA_HOME and JRE_HOME:

echo -e "\n## JAVA VARS -------------------- " >> ~/.bashrc
echo "export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk" >> ~/.bashrc
echo "export JRE_HOME=/usr/lib/jvm/jre" >> ~/.bashrc

# source it
. ~/.bashrc

Check your vars:

echo $JAVA_HOME
echo $JRE_HOME