How to install Java 14 on Ubuntu 18.14

How to install Java 14 on Ubuntu 18.14

Author : Hamza EL YAAQOUBI

2020, May 14    

In this guide, I will show you how to install properly the latest version of Java which is released actually. The current LTS Java version is 14.

JDK 14 is the open-source reference implementation of version 14 of the Java SE Platform as specified by JSR 389 in the Java Community Process.

JDK 14 reached General Availability on 17 March 2020.

The features and schedule of this release were proposed and tracked via the JEP Process, as amended by the JEP 2.0 proposal.

If you want to read all of JDK 14 features, go to the official documentation to get the releases notes on JDK 14 Release Note.

Let’s see how you can install Oracle JDK 14 on Ubuntu 18.14

Step 1 : Download Oracle JDK 14

You can download the latest release for the Java SE Platform directly from this url.

$> cd /tmp
$> mkdir java14
$> cd java14
$> wget --no-check-certificate -c --header  "Cookie: oraclelicense=accept-securebackup-cookie"  https://download.oracle.com/otn-pub/java/jdk/14.0.1+7/664493ef4a6946b186ff29eb326336a2/jdk-14.0.1_linux-x64_bin.deb

If wget command isn’t installed :

$> sudo apt -y install wget

Step 2 : Install Oracle JDK 14

Now you’re downloaded your archive, you cas run the following commands to install Oracle JDK 14 on your system :

$> cd /tmp/java14
$> sudo apt install ./jdk-14.0.1_linux-x64_bin.deb

Step3 : Configure Oracle JDK 14 as default on ubuntu

To configure the later install of Oracle JDK 14, run the following commands :

$> sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-14.0.1/bin/java 2
$> sudo update-alternatives --config java

Step 4 : Configure Oracle JDK 14 as default Java compiler for ubuntu desktop

Run the following commands :

$> sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-14.0.1/bin/jar 2
$> sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-14.0.1/bin/javac 2
$> sudo update-alternatives --set jar /usr/lib/jvm/jdk-14.0.1/bin/jar
$> sudo update-alternatives --set javac /usr/lib/jvm/jdk-14.0.1/bin/javac

Step 5 : Check installed Java version

Run the commands below to check if Ubuntu recognizes Java :

$> java -version

If you have many versions of Java installed on your system :

$> sudo update-alternatives --config java

To change the version, just choose a selection between all options. (cf : the screenshot above)

Step 6 : Set Java environment

Create and update a new file as below :

$> sudo vi /etc/profile.d/jdk14-0-1.sh
$> export JAVA_HOME=/usr/lib/jvm/jdk-14.0.1/
$> export PATH=$PATH:$JAVA_HOME/bin

Finally, source the created file :

source /etc/profile.d/jdk14-0-1.sh

Enjoy the new Oracle JDK 14 !