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.
1 |
sudo add-apt-repository ppa:webupd8team/java |
If you’re behind a proxy, you can try to add -E parameter to the command
1 2 3 |
export http_proxy=http://<proxy>:<port> export https_proxy=http://<proxy>:<port> sudo -E add-apt-repository ppa:webupd8team/java |
1.2. Update Package Repository
Issue below command to update your package repository
1 |
sudo apt-get update |
1.3. Install Oracle Java 9 on Ubuntu 16.04
To install Java 9 on Ubuntu 16.04, we can run the following command:
1 |
sudo apt-get install oracle-java9-installer |
During installation, we will need to confirm the license agreement as follows:

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:

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:
1 |
sudo update-alternatives --config java |
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.

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 |
java -version |
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:
1 |
export JAVA_HOME=/usr/lib/jvm/java-9-oracle |
To get the variables effective right away rather than a reboot, we can run the below command:
1 |
source /etc/environment |
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:
1 2 3 |
wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" \ http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz \ -O jdk-9_linux-x64_bin.tar.gz |
2.2. Move and Extract The Java 9 Archive Package
We will need to move the archive package to appropriate location, for example: /opt
1 |
sudo mv jdk-9_linux-x64_bin.tar.gz /opt/ |
And then change to that directory and extract the package:
1 2 |
cd /opt/ sudo tar -xzf jdk-9_linux-x64_bin.tar.gz |
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:
1 |
sudo update-alternatives --install /usr/bin/java java /opt/jdk-9/bin/java 1000 |
In addition, we should also register the javac, javadoc and javap with the tool also:
1 2 3 |
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk-9/bin/javac 1000 sudo update-alternatives --install /usr/bin/javadoc javadoc /opt/jdk-9/bin/javadoc 1000 sudo update-alternatives --install /usr/bin/javap javap /opt/jdk-9/bin/javap 1000 |
And next, let set the Java 9 as default Java by invoking the following commands:
1 |
sudo update-alternatives --config java |
The command will list all the Java exists in our environment and require us to confirm which version will be set default as below:

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:
1 |
update-alternatives: using /opt/jdk-9/bin/java to provide /usr/bin/java (java) in manual mode |
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:
1 |
java -version |
That is a command to check version and we should see the output similarly as below:
1 2 3 4 |
vagrant@vagrant:/opt$ 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) |
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:
1 2 |
export JAVA_HOME=/opt/jdk-9 export PATH=$PATH:$JAVA_HOME/bin |
Because the file will be loaded automatically when system boots, we can execute the following command to get our variable effective right away:
1 |
source /etc/environment |
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)