This quick tutorial is going to cover how to install Oracle Java 9 on CentOS, RHEL. The installation can be performed by using one of the following processes:
- From archive binaries (.tar.gz)
This allows us to install a private version of the JDK for the current user into any location, without affecting other JDK installations
- From RPM packages (.rpm)
This allows us to perform a systemwide installation of the JDK for all users and requires root access. RPM-based Linux platforms are based on Red Hat and SuSE.
In this tutorial, we are getting through both of processes to install Java 9 on CentOS, RHEL. And if you’re looking for guidelines how to install Oracle Java 9 on Ubuntu, please read the instruction at Install Oracle Java 9 on Ubuntu 16.04 LTS (Xenial Xerus).
1. Install Oracle Java 9 On CentOS From Archive Binaries(.tar.gz)
1.1. Download Java 9 Archive Binary
To download the Java 9 archive binary, we can go to Java 9 official website of Oracle, select the appropriate version and then download. Or you can download the archive binary by using wget command as follows:
1 2 3 |
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 |
1.2. Move and Unpack The Archive Binary
Change the directory to the location where you want to install the JDK, then move the .tar.gz archive binary to the current directory, for example, we will move the archive binary above to /opt
1 |
sudo mv jdk-9_linux-x64_bin.tar.gz /opt/ |
Next, let unpack the file:
1 2 |
cd /opt/ sudo tar -xzf jdk-9_linux-x64_bin.tar.gz |
1.3. Set up Java Environment Variables
Because there are a lot of applications requires Java environment variables to work, we will set up them here by adding the following commands at the end of /etc/environment file:
1 2 |
export JAVA_HOME=/opt/jdk-9 export PATH="$PATH:$JAVA_HOME/bin" |
Notice that the /etc/environment file will be automatically loaded when the system boots or we can issue the following command to reload the file right away:
1 |
source /etc/environment |
1.4. Verify The Installation
To verify the installation, we can run the following command:
1 |
java -version |
The output will be:

Java 9 version
1.5. Configure Default Java with Alternatives (optional)
As you may know, the alternatives is a tool for managing different software packages that provide the same functionality and we can use it to ensure that only one Java Development Kit (JDK) is set as the system default at one time in case we have different versions of Java exist in our environment. Because we install Oracle Java 9 from archive binary, we will need to register Java with the alternatives manually:
1 |
sudo alternatives --install /usr/bin/java java /opt/jdk-9/bin/java 1000 |
And next, let’s register the javac, javadoc, and javap:
1 2 3 |
sudo alternatives --install /usr/bin/javac javac /opt/jdk-9/bin/javac 1000 sudo alternatives --install /usr/bin/javadoc javadoc /opt/jdk-9/bin/javadoc 1000 sudo alternatives --install /usr/bin/javap javap /opt/jdk-9/bin/javap 1000 |
We have just registered our Java 9 with alternatives, now let’s use it to configure the default JDK by running the below command:
1 |
sudo alternatives --config java |
The confirmation is displayed as follows:

Use Alternatives to configure Java
Because there is only one version of Java in our environment, we only see one record. If we have more versions of Java, they will be listed out and we can select the active version by input the number accordingly.
We can configure the same for other Java commands such as javac, javadoc, javap. And that were all steps to install Java 9 on CentOS, RHEL.
2. Install Oracle Java 9 On CentOS From RPM Package
You must log in as a root user to install Java 9 on CentOS, RHEL from a RPM package.
2.1. Download Java 9 RPM Package
We can download the Java 9 RPM package from its official website or simply use the wget command as follows:
1 2 3 |
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 |
2.2. Install The Java 9 RPM Package
We can install the package using the following command:
1 |
rpm -ivh jdk-9_linux-x64_bin.rpm |
2.3. Verify
We can verify whether the installation was successful or not by executing the following command:
1 |
java -version |
The output is:
1 2 3 4 5 |
[vagrant@localhost ~]$ 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) [vagrant@localhost ~]$ |
2.4. Configure Default Java
If our environment has many versions of Java, we will need to configure the default one and we can do it by using the alternatives tool, for example:
1 |
sudo alternatives --config java |
We may see the confirmed messages on the terminal as follows:

Alternatives set default Java
We can see that there are two versions of Java in our environment. And if we want to change the default one, we can input the number accordingly to the terminal.
2.5. Set up Java Environment Variables
To set up Java environment variables, we can append the following commands to the end of the /etc/environment file:
1 2 |
export JAVA_HOME=/usr/java/jdk-9/ export PATH="$PATH:$JAVA_HOME/bin" |
To get effective right away rather than to wait until the /etc/environment gets reloaded when system boots, we can run the below command:
1 |
source /etc/environment |
3. Conclusions
The tutorial has illustrated us two different ways to install Oracle Java 9 on CentOS, RHEL and we can see that using the RPM process seem to be more simple and is suitable for performing a systemwide installation of the JDK for all users as well.
Below are other Java 9 related tutorials for your references:
Set Up Eclipse, IntelliJ And NetBeans For Java 9
Create Immutable Lists In Java 9 By Static Factory Methods
Java 9 Example With Maven And JUnit 5