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. 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

Next, let unpack the file:

 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:

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.4. Verify The Installation

To verify the installation, we can run the following command:

The output will be:

Install Oracle Java 9 on CentOS RHEL 7 - Verify Java 9 Version

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:

And next, let’s register the javac, javadoc, and javap:

We have just registered our Java 9 with alternatives, now let’s use it to configure the default JDK by running the below command:

The confirmation is displayed as follows:

Install Java 9 on CentOS, RHEL - Use Alternatives to configure Java

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:

 2.2. Install The Java 9 RPM Package

We can install the package using the following command:

2.3. Verify

We can verify whether the installation was successful or not by executing the following command:

The output is:

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:

We may see the confirmed messages on the terminal as follows:

Install Oracle Java 9 on CentOS RHEL 7 - Alternatives Java

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:

To get effective right away rather than to wait until the /etc/environment gets reloaded when system boots, we can run the below command:

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

 

0 0 vote
Article Rating