How To Manually Install Oracle Java 9 On Ubuntu 16.04

Install Oracle Java 9

https://askubuntu.com/questions/56104/how-can-i-install-sun-oracles-proprietary-java-jdk-6-7-8-or-jre
https://tecadmin.net/install-oracle-java-8-ubuntu-via-ppa/
https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04
https://fribeiro.org/tech/2018/02/07/nextcloud-full-text-elasticsearch/

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Download the 64-bit (or 32-bit) Linux “compressed binary file” into your home directory – it has a “.tar.gz” file extension.

Uncompress it:

$ tar -xvf jdk-9.0.4_linux-x64_bin.tar

The JDK 8 package is extracted into ./jdk-9.0.4 directory. N.B.: Check carefully this folder name since Oracle seem to change this occasionally with each update.

Now move the JDK 8 directory to /usr/lib

$ sudo mkdir -p /usr/lib/jvm
$ sudo mv ./jdk-9.0.4 /usr/lib/jvm/

Now run:

$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-9.0.4/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-9.0.4/bin/javac" 1
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk-9.0.4/bin/javaws" 1

This will assign Oracle JDK a priority of 1, which means that installing other JDKs will replace it as the default. Be sure to use a higher priority if you want Oracle JDK to remain the default.

Correct the file ownership and the permissions of the executables:

$ sudo chmod a+x /usr/bin/java
$ sudo chmod a+x /usr/bin/javac
$ sudo chmod a+x /usr/bin/javaws
$ sudo chown -R root:root /usr/lib/jvm/jdk-9.0.4

N.B.: Remember – Java JDK has many more executables that you can similarly install as above. java, javac, javaws are probably the most frequently required. This answer lists the other executables available.

Run:

$ sudo update-alternatives --config java

You will see output similar to the one below – choose the number of jdk-9.0.4 – for example 3 in this list (unless you have have never installed Java installed in your computer in which case a sentence saying “There is nothing to configure” will appear):

$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
* 2            /usr/lib/jvm/jdk1.7.0/bin/java                   1         manual mode
  3            /usr/lib/jvm/jdk1.8.0/bin/java                   1         manual mode

Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk1.8.0/bin/java to provide /usr/bin/java (java) in manual mode

Repeat the above for:

sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Then,

$ sudo nano /etc/environment

ATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/game$ JAVA_HOME=”/usr/lib/jvm/jdk-9.0.4″

$ source /etc/environment

You can now test whether the environment variable has been set by executing the following command:

$ echo $JAVA_HOME

This will return the path you just set.

Check java version:

$ java -version

Output will be something like below:

java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

2 thoughts on “How To Manually Install Oracle Java 9 On Ubuntu 16.04

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.