In this post:

  • Search available Openjdk packages
  • install Openjdk 9 by - sudo apt-get install openjdk-9-jdk
  • Check java version
  • Check and set JAVA_HOME

You can check this video of installation of Java 9 on Ubuntu 16:
install OpenJDK 9 on Ubuntu 16

Update November 2019: The correct way to install Oracle JDK on Ubuntu

Search available Openjdk packages

By default Ubuntu / Linux Mint is using OpenJDK. You can check for all available versions simply by:

  • Open terminal CTRL+ALT+T
  • Type command:
apt-cache search openjdk
  • Choose OpenJDK 9 version from the results:

default-jdk - Standard Java or Java compatible Development Kit
default-jdk-doc - Standard Java or Java compatible Development Kit (documentatio     ***
openjdk-9-doc - OpenJDK Development Kit (JDK) documentation
**openjdk-9-jdk - OpenJDK Development Kit (JDK)**
***
oracle-java7-installer - Oracle Java(TM) Development Kit (JDK) 7
oracle-java6-installer - Oracle Java(TM) Development Kit (JDK) 6
oracle-java8-installer - Oracle Java(TM) Development Kit (JDK) 8
oracle-java9-installer - Oracle Java(TM) Development Kit (JDK) 9

Openjdk 9 installation

Install is done by this command:

sudo apt-get install openjdk-9-jdk

note you may face error like:

Errors were encountered while processing:
 /var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_i386.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

you can try to install by :

sudo apt-get -o Dpkg::Options::="--force-overwrite" install openjdk-9-jdk

or by (the files could be different for you i.e. openjdk-9-jdk_9~b114-0ubuntu1_amd64.deb):

sudo apt install openjdk-9-jdk
sudo dpkg --configure -a
sudo dpkg -i --force-overwrite '/var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_i386.deb'

Check java version

Installation of java can be tested by several commands:

java -version

result is

openjdk version "9-internal"
OpenJDK Runtime Environment (build 
9-internal+0-2016-04-14-195526.buildd.src)
OpenJDK Client VM (build 9-internal+0-2016-04-14-195526.buildd.src, 
mixed mode)
which java

result is

/usr/bin/java

This is symbolic link put in the system path by Ubuntu for the JDK:

lrwxrwxrwx  1 root   root          22 May 20  2016 java -> /etc/alternatives/java
lrwxrwxrwx  1 root   root          23 May 20  2016 javac -> /etc/alternatives/javac

Check and set JAVA_HOME

JAVA_HOME is vital for java programs and shows which version shoud be used. In order to set JAVA_HOME add this line:

JAVA_HOME="/usr/lib/jvm/java-9-openjdk-i386"

to the end of .bashrc.

You can check which java is installed by:

update-alternatives --config java

Before

echo $JAVA_HOME
/usr/lib/jvm/default-java # or nothing

Set JAVA_HOME 32b by

sudo echo export JAVA_HOME="/usr/lib/jvm/java-9-openjdk-i386" >> ~/.bashrc
source ~/.bashrc

After

echo $JAVA_HOME
/usr/lib/jvm/java-9-openjdk-i386

Note that for Ubuntu 64 you will have java-9-openjdk-amd64

sudo echo export JAVA_HOME="/usr/lib/jvm/java-9-openjdk-amd64" >> ~/.bashrc
source ~/.bashrc

After

echo $JAVA_HOME
/usr/lib/jvm/java-9-openjdk-amd64