How to Install Java 11 on Ubuntu 18.04

How to Install OracleJDK 11 and OpenJDK 11 on Ubuntu 18.04

Overview

In this tutorial, you will learn how to install Java SDK 11 on Ubuntu 18.04, with instructions covering both Oracle JDK and OpenJDK.

Installing OpenJDK 11

The default JDK (Java Development Kit) and JRE (Java Runtime Environment) for Ubuntu 18.04 is OpenJDK. Starting with this release of the SDK, this is the preferred one for anyone not running enterprise licenses.

With the release of Java 11, Oracle decided to make a major shift in their licensing. Prior to Java 11, anyone could run Oracle JDK freely and it was the most popular choice as a result.

With the new license, a commercial license is required to any application on OracleJDK. Thankfully, OpenJDK is now nearly identical to OracleJDK, due to efforts from Oracle and major contributors to the open source project.

As a result of the changes to OpenJDK, it is now the preferred JDK to develop and run applications that will not need the enterprise support from Java.

The JDK has two separate packages that target different computer configurations.

  • Standard
  • Headless

For those running Ubuntu 18.04 with a desktop graphical interface, the standard installation will suite your needs. Headless, on the other hand, is specific to servers without a graphical desktop installed.

What separates standard from headless is the latter has had all of the graphical interface libraries removed, as they wouldn’t be needed to begin with. This allows for a much smaller installation footprint, and is ideal for running Java applications in containers.

To install OpenJDK, you may use one of the following commands.

sudo apt install default-jdk

To install the headless package of OpenJDK, run the following command.

sudo apt install default-jdk-headless

Alternatively, the Java Runtime Environment can be installed rather than the full-blown Java Development Environment.

sudo apt install default-jre

And for the headless variant of the JRE

sudo apt install default-jre-headless

Installing OracleJDK 11

Starting with this release of the Java JDK, a paid commercial license is needed for running any applications.

The OracleJDK package for Java 11 is no longer made freely available from Oracle. However, Linuxuprising has added the installation package to their PPA, though as this isn’t an official channel you are best to work with Oracle to gain access to the packages in an enterprise environment.

Install the Java PPA from Linux Uprising.

sudo add-apt-repository ppa:linuxuprising/java

Update Apt’s repository cache

sudo apt update

Install OracleJDK 11

sudo apt install oracle-java11-installer