In this tutorial we’ll learn how to install Java on CentOS 7. We will also install and configure its prerequisites. There are two standard types of installations, JRE (Java Runtime Environment) and JDK (Java Development Kit). Like the base model car, JRE enables the ability to create Java Applications for different types of deployments using minimal core tools to accomplish the task. JDK is a fully loaded Development Kit that has everything that JRE has plus additional resources to create/secure Applications and Applets.
I recommend to use a minimal CentOS server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install Java on CentOS 7
Step 1. First, ensure your system is fully up-to-date by running the following:
yum -y update
Step 2. Installing Java.
Select one of the following versions of Java JRE, version 8 being the latest:
yum install java-1.8.0-openjdk yum install java-1.7.0-openjdk yum install java-1.6.0-openjdk
Select one of the following versions of Java JDK, version 8 being the latest:
yum install java-1.8.0-openjdk-devel yum install java-1.7.0-openjdk-devel yum install java-1.6.0-openjdk-devel
Another alternative Java install is with Oracle. However, we would need to download the file from the Oracle site:
cd /opt 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/8u51-b16/jre-8u51-linux-x64.tar.gz"
We must extract the files with the following command:
tar xvf jre-8u51-linux-x64.tar.gz chown -R root: jre1.8.0_51
After extracting archive file use alternatives command to install it:
alternatives --install /usr/bin/java java /opt/jre1.8.0_51/bin/java 1
Step 3. Setup JAVA_HOME on CentOS 7.
We can easily set the environment variables using the export command as shown below:
export JAVA_HOME=/usr/java/jdk1.8.0_51/ export PATH=$PATH:$JAVA_HOME
Verify that your implementations are correct with the following command:
Congratulation’s! You have successfully configured Java (JRE or JDK) on your CentOS 7 server.