How To Install Java with apt on Ubuntu 18.04

Ekaterina Neverova
June 26, 2020

Java and JVM (Java Virtual Machine) are required for many types of software, including Tomcat, Jetty, Glassfish, Cassandra and Jenkins.

This guide will help you learn how to install different versions of the Java Runtime Environment (JRE) and Java Developer Kit (JDK) with apt.

Java Runtime Environment

The easiest way to install Java is to use the version included in the Ubuntu package. By default, Ubuntu 18.04 includes Open JDK (open source JRE and JDK version).

This package installs OpenJDK version 10 or 11.

  • Until September 2018, OpenJDK 10 was installed.
  • After September 2018, OpenJDK 11 is installed.

First, update the package lists:

sudo apt update

Then you need to check if Java is already installed:

java -version

If Java was newer installed, yo’ll see the following results:

Run the following command to install OpenJDK:

sudo apt install default-jre

Type y (yes) and press Enter to resume installation.

This command installs the Java Runtime Environment (JRE). It allows you to run almost any Java software.

Now check the Java version:

java -version

JRE is installed!

Java Development Kit

To compile and run some specific Java programs in addition to the JRE, you may need the Java Development Kit (JDK). To install the JDK, run the following command, which also installs the JRE:

sudo apt install default-jdk

Type y (yes) and press Enter to resume installation.

This command installs the Java Development Kit (JDK).

Now check JDK version with command:

javac -version

JDK is installed!

Have questions before you deploy? Contact our Customer Success team to get answers.
We use cookies to provide our services and for analytics and marketing. To find out more about our use of cookies, please see our Privacy Policy. By continuing to browse our website, you agree to our use of cookies.