In this tutorial, we are going to learn to install JAVA 9 on Linux machines. Java 9 released on 21, September 2017 with lots of new features ( For complete list,visit OFFICIAL JAVA WEBSITE ). In our previous tutorial, we have also discuss the installation of Java 7 & 8 on Linux, if you wish to install any of those versions, read the tutorial HERE.

Now moving on to Java 9 , we can perform the installation using two methods i.e.

1- Using the RPM provided on Official Oracle Java website.

Using this method, we can install Java 9 on CentOS/RHEL machines only.

2- Using the .tar.gz archive binaries

With this method, we can install multiple versions of java on our system. Also using this method, we can install Java 9 on CentOS/RHEL as well as other Linux distributions such as Ubuntu, Debian etc

So let's start with 1st method,

 

1- Using the RPM

Though we can skip this step but if you want only single version of java on your system, than remove any older versions of the Java,

$ sudo yum remove java*

Now we need to download the RPM package file for Java 9 from Official Oracle Website. To download the package, open the terminal & execute the following command,

$ wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" \http://download.oracle.com/otn-pub/java/jdk/9+181/jdk-9_linux-x64_bin.rpm \-O jdk-9_linux-x64_bin.rpm

This command accepts the Oracle License and then download the rpm for Java 9 onto the system. Once the package has been downloaded, install it using

$ sudo rpm -ivh jdk-9_linux-x64_bin.rpm

After installation has been completed successfully, we can than check the version of java to confirm,

$ java -version

java version "9"

Java(TM) SE Runtime Environment (build 9+181)

Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

The output shows that Java 9 has been installed on the system successfully. Now let's discuss the 2nd method

( Also read : Wildfly 10.1.0 installation on Linux )

 

2- Using the .tar.gz archive binaries

We now need to download the .tar.gz archives from Official Oracle Website like we downloaded the rpm package above. To download the archive binaries, open terminal & run

 wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/9+181/jdk-9_linux-x64_bin.tar.gz -O jdk-9_linux-x64_bin.tar.gz

We can install Java 9 in any directory we want to using this method, but we will be installing it in '/opt' directory. So copy the downloaded package there & extract it,

$ cp jdk-9_linux-x64_bin.tar.gz /opt

$ sudo tar -xvf jdk-9_linux-x64_bin.tar.gz

We will now install Java 9 using alternatives –install,

$ cd jdk-9

$ sudo alternatives --install /usr/bin/java java /opt/jdk-9/bin/java 2

After the java installation, we can now configure the default Java that is to be used ,

$ sudo alternatives --config java

Than you will shown all the instances on Java installed on the sytem, select the default java instance by selecting the corresponding number.

Note :- This command can also be used to change the default Java instance, in case we have installed Java 9 using the RPM method & have opted to keep the older version of java as well.

 

Setting up Java variables

This is the last step of installation & has to be followed irrespective of the methods used to install Java 9 i.e. we need to setup the 'JAVA_HOME' , 'JRE_HOME' & 'PATH' variables on our systems. To setup the variables make the entries mentioned below at the bottom in file '~/.bash_profile', where '~' is the home of the user,

$ vi ~/bash_profile

export JAVA_HOME=/opt/jdk-9

export JRE_HOME=/opt/jdk-9/jre

export PATH=$PATH:/opt/jdk-9/bin:/opt/jdk-9/jre/bin

If we have used the rpm method for installation, we need to make the following entries in the same file (~/bash_profile) as the location for Java 9 is different when installed via rpm package,

export JAVA_HOME=/usr/java/jdk-9/

export JRE_HOME=/usr/java/jdk-9/jre

export PATH="$PATH:/usr/java/jdk-9/bin:/usr/java/jdk-9/jre/bin"

Once the setting have been saved, we can use the new Java 9 installation on the system. With this our tutorial is now complete, please leave your queries/questions below.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of you hard earned money: [paypal-donation]

Linux TechLab is thankful for your continued support.