How To Install Oracle Java JDK 12 / 11 / 8 on CentOS 7 / RHEL 7

Today we will be looking into the installation of Oracle Java JDK on RHEL 7 / CentOS 7. Java JDK is the most important base for the developers.

This guide will be more useful for them to set up a development environment when they especially use RHEL 7 or CentOS 7.


Install the wget package.

yum install -y wget

Download Oracle Java JDK

You can either use command line or browser to download the JDK, better to use the browser, the easiest one.

Visit the Oracle JDK page to download.

Oracle Java JDK 12:

Download Oracle JDK 12 (v12.0.1)

Oracle Java JDK 11 (LTS):

Download Oracle JDK 11 (v11.0.3) (Login Required)

Oracle Java JDK 8:

Download Oracle JDK 8 (v8u211) (Login Required)

If you still want to use the command line, use the below command.

### Oracle Java JDK 12 ###

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"

### Oracle Java JDK 11 ###


### Oracle Java JDK 8 ###


Extract the downloaded JDK archive to the desired directory (Ex. /usr/)

### Oracle Java JDK 12 ###

tar -zxvf jdk-12.0.1_linux-x64_bin.tar.gz -C /usr

### Oracle Java JDK 11 ###

tar -zxvf jdk-11.0.3_linux-x64_bin.tar.gz -C /usr

### Oracle Java JDK 8 ###

tar -zxvf jdk-8u211-linux-x64.tar.gz -C /usr

Install Oracle Java

Install Java with the alternatives commands. Below command will install the Java on your system.

### Oracle Java JDK 12 ###

update-alternatives --install /usr/bin/java java /usr/jdk-12.0.1/bin/java 1

### Oracle Java JDK 11 ###

update-alternatives --install /usr/bin/java java /usr/jdk-11.0.3/bin/java 2

### Oracle Java JDK 8 ###

update-alternatives --install /usr/bin/java java /usr/jdk1.8.0_211/bin/java 3

Set Default Oracle Java Version

Set the default java using the below command.

alternatives --config java

Select the latest Java:

If your system has multiple versions of Java installed, then the above command may list you all Java versions, like below.

There are 5 programs which provide 'java'.

  Selection    Command
   1           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-
   3           /usr/jdk-12.0.1/bin/java
   4           /usr/jdk-11.0.3/bin/java
   5           /usr/jdk1.8.0_211/bin/java

Enter to keep the current selection[+], or type selection number: 3

Choose the one Java version to be set default. Enter the number below selection column to select the default Java version. Here, I chose 3 for Oracle JDK 12.

Verify the Java

Once you set up the alternatives. Check the java version installed using the following command.

java -version


Oracle JDK 12:

java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

Oracle JDK 11:

java version "11.0.3" 2019-04-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.3+12-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.3+12-LTS, mixed mode)

Oracle JDK 8:

java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

Setup Environmental Variable

The most important part has come now, it should be set before the installation of any Java-based applications.

To set JAVA environment variables, create a new file under /etc/profile.d directory.

vi /etc/profile.d/

Place the variables based on the JDK location and version.

Oracle JDK 12:

export PATH=$PATH:/usr/jdk-12.0.1/bin 
export JAVA_HOME=/usr/jdk-12.0.1
export J2SDKDIR=/usr/jdk-12.0.1

Oracle JDK 11:

export PATH=$PATH:/usr/jdk-11.0.3/bin
export JAVA_HOME=/usr/jdk-11.0.3
export J2SDKDIR=/usr/jdk-11.0.3

Oracle JDK 8:

export PATH=$PATH:/usr/jdk1.8.0_211/bin
export JAVA_HOME=/usr/jdk1.8.0_211
export JRE_HOME=/usr/jdk1.8.0_211/jre/
export J2SDKDIR=/usr/jdk1.8.0_211
export J2REDIR=/usr/jdk1.8.0_211/jre

Load the environments into the current session.

source /etc/profile.d/

To set the environment variables permanent for a particular user, place the above in ~/.bash_profile file.


I hope you have learned how to install Oracle Java on CentOS 7 system. Share you feedback in the comments section.

centos 7developmentjavajdkoraclejava
Comments (1)
Add Comment
  • STLShawn

    Wonderful article. Very straightforward and to the point. Fantastic.