In this article, I’d like to share how to install Oracle Java 9 on Ubuntu 16.04. Java 9 will be released on 2017; however, it’s good for anyone who wants to try some new features of Java 9 with the new early access version.

If you’re looking for guides how to install Oracle Java 9 on other Linux distros, you can read Install Oracle Java 9 on CentOS, RHEL 7.

1. Install Java 9 on Ubuntu 16.04  with Apt-get

1.1. Add the WebUpd8 Oracle Java PPA

To install Oracle Java 9 on Ubuntu 16.04, we will need to add the WebUpd8 PPA repository first. We can do that simply by running the following command.

If you’re behind a proxy, you can try to add -E parameter to the command

1.2. Update Package Repository

Issue below command to update your package repository

1.3. Install Oracle Java 9 on Ubuntu 16.04

To install Java 9 on Ubuntu 16.04, we can run the following command:

During installation, we will need to confirm the license agreement as follows:

 Confirm License Aggreement

Confirm License Agreement

We need to hit the Enter to continue. After that we also need to accept the  license agreement by select <Yes> and hit Enter:

Confirm License Aggreement

Install Java 9 on Ubuntu 16.04 – Confirm License Agreement

1.4. Set Oracle Java 9 as Default

We can have multiple versions of Java installed on our PC, and we can configure which version is the default by using the command:

The command will list out all the available versions of Java is being installed in our environment and ask us for selecting the default one, and here is an example on my PC.

Install Oracle Java 9 on Ubuntu 16.04 - Configure Oracle Java 9 as default Java

Configure Oracle Java 9 as default Java

Currently, the default version is the Oracle Java 8. I change to Oracle Java 9 by entering 0.

1.5. Verification

We can verify the version of the default Java by executing:

1.6. Setup 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 the variables effective right away rather than a reboot, we can run the below command:

And that is the final step for us to install Java 9 on Ubuntu 16.04 by using apt-get.

2. Install Oracle Java 9 on Ubuntu 16.04 Manually

This section will cover how to install Oracle Java 9 on Ubuntu 16.04 manually from archive binaries.

2.1. Download Java 9 Archive Package (tar.gz)

You can obtain a Java 9 archive package from its official website using web browser or using the wget command as follows:

2.2. Move and Extract The Java 9 Archive Package

We will need to move the archive package to appropriate location, for example: /opt

And then change to that directory and extract the package:

2.3. Set Java 9 As Default Java

Our environment may have different versions of Java and we may need to set Java 9 as default Java, to do that we firstly will need to register it with the update-alternatives tool because we have just install Java 9 manually, for example:

In addition, we should also register the javac, javadoc and javap with the tool also:

And next, let set the Java 9 as default Java by invoking the following commands:

The command will list all the Java exists in our environment and require us to confirm which version will be set default as below:

Install Oracle Java 9 on Ubuntu 16.04 - Alternatives Set Default Java

Set Java 9 as Default on Ubuntu 16.04

We can see that there are two version of Java in our environment: Java 8 and Java 9 and currently the Java 8 is set as default. To set Java 9 as default, we can input the number 1 into the terminal and hit the Enter to confirm. The output will be:

2.4. Verify

To verify whether we have installed Java 9 on Ubuntu and set it as default Java correctly or not, let issue the following command:

That is a command to check version and we should see the output similarly as below:

2.5. Set up Java Environment Variables

This step is required to run some Java applications. Now, let’s set up the JAVA_HOME environment variable by appending the following commands at the end of /etc/environment file:

Because the file will be loaded automatically when system boots, we can execute the following command to get our variable effective right away:

And that is the final step for us to install Java 9 on Ubuntu 16.04.

 

3. Summary

We have tried to install Oracle Java 9 on Ubuntu 16.04. Note that Java 9 has just been released and with the above PPA, we can install the latest release of the Oracle Java 9.

4. References

http://www.java9countdown.xyz/

Set Up Eclipse, IntelliJ And NetBeans For Java 9

Create Immutable Lists In Java 9 By Static Factory Methods

Install MySQL on Ubuntu 16.04 (Xenial Xerus)

Install Maven on Ubuntu 16.04 LTS (Xenial Xerus)

Install Gradle on Ubuntu 16.04 LTS (Xenial Xerus)

Install Apache Ant on Ubuntu 16.04 LTS (Xenial Xerus)

 

0 0 vote
Article Rating