There are two different Java packages in Ubuntu repositories, Java Runtime Environment (JRE), and the Java Development Kit (JDK).

If you only want to run Java programs, then you need JRE, which contains only the Java Runtime Environment. Java developer should install JDK, which also includes the development/debugging tools and libraries.

We will see how to install default OpenJDK version available on Ubuntu 18.04.

Installing the Default OpenJDK (Java 11)

First, update theĀ aptĀ package index with:

$ sudo apt update 

Once the package index is updated install the default Java OpenJDK package with:

$ sudo apt install default-jdk 

Verify the installation, by running the following command which will print the Java version:

$ java -version 

The output will look something like this:

openjdk version "11.0.2" 2019-01-15 
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)

You should have successfully installed Java on your Ubuntu system.

Installing OpenJDK 8

Java 8 is still the most widely-used version of Java. If your application requires Java 8, you can install it by using below commands:

$ sudo apt update
$ sudo apt install openjdk-8-jdk