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.

Updating Repository Database

To install Java 12 on your debian/ubuntu system, you first need to update your repository package database by running the following commands:

root@codesposts:~$ add-apt-repository ppa:linuxuprising/java

root@codesposts:~$ apt update

Installing Java 12

After adding the PPA and updating, run the following command to install the java 12 on your debian/ubuntu system.

root@codespsots:~$ apt install oracle-java12-installer

Making Java 12 Default

If more than one versions of Java are installed on your system, you can make the Java 12 default by running the following command:

root@codesposts:~$ apt y install oracle-java12-set-default

Verifying The Version

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

root@codesposts:~$ java --version

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

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.

root@codesposts:~$ vim /etc/profile.d/jdk.sh

Then add the following text in the file and Save it.

export JAVA_HOME=/usr/lib/jvm/java-12-oracle
export PATH=$PATH:$JAVA_HOME/bin

Then Run the following command to update the environment variables

root@codesposts:~$ source /etc/profile.d/jdk.sh