This comprehensive Linux guide expects that you run the following commands as root user but if you decide to run the commands as a different user then ensure that the user has sudo access and that you precede each of the privileged commands with sudo

Java is one of the world’s most popular programming language. Java SE 12 is the result of an industry-wide development effort involving open review, weekly builds, and extensive collaboration between Oracle engineers and members of the worldwide Java developer community via the OpenJDK Community and the JCP.

In this tutorial, we will guide you about how to install java 12 JDK/JRE on Red-Hat Based Distributions, CentOS and Fedora.

Downloading Java 12 Binary

You can run the following commands to download the Java 9 JDK and JRE .rpm files on your system.

[email protected]:~$ wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/12.0.2+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.2_linux-x64_bin.rpm

Installing Java 12 JDK/JRE

Follow the instructions below to install the Java SE 9 JDK/JRE on your system

On RHEL/CentOS 7

To install Java 12 JDK/JRE on your RHEL/CentOS 7, run the following commands:

[email protected]:~$ yum localinstall jdk-12.0.2_linux-x64_bin.rpm

On Fedora

To install Java 12 JDK/JRE on your Fedora, run the following commands:

[email protected]:~$ rpm -ivh jdk-12.0.2_linux-x64_bin.rpm

Making Java 12 Default

After installation, you can make the Java 12 the default version by running the command below:

[email protected]:~$ alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
 + 1           /opt/jdk1.8.0_201/bin/java
   2           /usr/java/jdk-11.0.4/bin/java
*  3           /usr/java/jdk-12.0.2/bin/java


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

Enter 3 and press Enter.

Setting Up Environment Variables

After installing, we need to set the environment variables and the executable files path into your system $PATH variable, by running the below commands.

[email protected]:~$ vim /etc/environment

Add the following line to the file:

JAVA_HOME="/usr/java/jdk-12.0.2"

Now run the following command:

[email protected]:~$ source /etc/environment

Verifying The Version

You can verify the Java 9 version installed on your system by running the following command:

[email protected]:~$ java --version

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