How to Install Java on CentOS 7

r00t July 31, 2017

Install Java on CentOS 7

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:; oraclelicense=accept-securebackup-cookie" /""

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/

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.


The Tags:

Leave a Comment

Comments are closed.