Install Java on CentOS 7

Java is the popular programming language owned by Oracle. Java is used to build cross-platform applications. Over 3 billion devices run on Java. In this tutorial, we are going to install Java on CentOS 7 using different methods.

Java has following three editions:

Standard Edition(SE).

Micro Edition(ME).

Enterprize Edition(EE).

Following two implementations available for Java:

Oracle Java.

OpenJDK Java.

In this tutorial we are going to install Standard Edition (SE). There is no more difference in Oracle Java and OpenJDK Java as Oracle Java provides some additional enterprise features.

Prerequisites

Before you start to install Java on CentOS 7. You must have the non-root user account on your system with sudo privileges.

You should have curl package installed on your system. We are going to use curl package to download Oracle JRE/JDK from their official website. Install it by using following command.

sudo yum install curl

Install OpenJDK 8

Currentally, OpenJDK 8 is the latest LTS version of OpenJDK. Here we are going to install it with yum package manager.

Install OpenJDK 8 JRE

To install OpenJDK 8 JRE package run following command.

NOTE : If you have installed OpenJDK 8 JDK then we do not need to install OpenJDK 8 JRE As JRE is the subset of JDK.

sudo yum install java-1.8.0-openjdk

Install OpenJDK 8 JDK

Run the following command to install OpenJDK 8 using yum package manager:

sudo yum install java-1.8.0-openjdk-devel

Confirm the installation and check the version typing following command.

java -version

Install OpenJDK 7

Install OpenJDK 7 JDK

Run the following command to install OpenJDK 7 using yum package manager:

sudo yum install java-1.8.0-openjdk-devel

Install OpenJDK 7 JRE

To install OpenJDK 7 JRE package run following command.

NOTE : If you have installed OpenJDK 7 JDK then we do not need to install OpenJDK 8 JRE As JRE is the subset of JDK.

sudo yum install java-1.8.0-openjdk

Install Oracle Java 8

At the time writing this tutorial Oracle Java 8 is the latest LTS version of Oracle Java. Now to install Oracle Java 8 follow the instractions given below.