How To Install OpenJDK 11 on Ubuntu 18.04

Introduction

In this tutorial we learn how to install OpenJDK 11 on Ubuntu 18.04 from Ubuntu repository. Java 11 is the current LTS (Long Term Support) version of Java.

Update Apt Package Index

First of all update apt package index using the command below.

sudo apt-get update

or we can also use apt command below.

sudo apt update

Searching OpenJDK Packages on Ubuntu Repository

To get list of available openjdk packages we can use command below.

sudo apt search ^openjdk-11

We will get output similar to below.

To search OpenJDK packages on Ubuntu we can also use apt-cache command below.

sudo apt-cache search ^openjdk-11

The output will be a little bit different that what we got from apt search command.

You can see sample output of this search below.

Install OpenJDK 11 on Ubuntu 18.04

In this section we learn how to install OpenJDK 11 package on Ubuntu 18.04. We will learn how to install multiple alternatives of Java 11 on Ubuntu 18.04.

Install OpenJDK 11 Java Development Kit (JDK)

To install OpenJDK 11 JDK package we can use the command below. For this tutorial I will install this package.

There are alternative packages that you can install we will learn about each method below.



<img loading="lazy" width="1252" height="450" src="https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-03.png" alt="install openjdk 11 ubuntu 18.04 - apt-get install openjdk-11-jdk" class="wp-image-1535" srcset="https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-03.png 1252w, https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-03-640x230.png 640w, https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-03-768x276.png 768w" sizes="(max-width: 1252px) 100vw, 1252px" /> </figure> 

To install OpenJDK 11 JDK headless package we can use the coomand below. You can install JDK headless if you need to develop or compile application that doesn't have GUI like webapps

sudo apt-get install openjdk-11-jdk-headless


<div class="wp-block-image">
  <figure class="aligncenter size-full"><img loading="lazy" width="1248" height="287" src="https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-04.png" alt="Install openjdk 11 ubuntu 18.04 - apt-get install openjdk-11-jdk-headless" class="wp-image-1536" srcset="https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-04.png 1248w, https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-04-640x147.png 640w, https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-04-768x177.png 768w" sizes="(max-width: 1248px) 100vw, 1248px" /></figure>
</div>

### Install OpenJDK 11 Java Runtime Environment (JRE)

To install OpenJDK 11 JRE package we can use the command below. You can install JRE if you need to run java application on desktop that using GUI.

Install openjdk 11 ubuntu 18.04 - apt-get install openjdk-11-jre

To install OpenJDK 11 JRE Headless package we can use the command below. You can install JRE headless to run Java application on server.



<img loading="lazy" width="1242" height="288" src="https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-06.png" alt="Install openjdk 11 ubuntu 18.04 - apt-get install openjdk-11-jre-headless" class="wp-image-1538" srcset="https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-06.png 1242w, https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-06-640x148.png 640w, https://www.howtodojo.com/wp-content/uploads/2020/07/install-openjdk-11-ubuntu-18.04-06-768x178.png 768w" sizes="(max-width: 1242px) 100vw, 1242px" /> </figure> 

## Compile and Run Java 11 Application

In this section we will create a simple Java application, compile and run using openJDK `javac` and `java` application.

First, create new file named `HelloHowtoDojo.java` with contents below

class HelloHowtoDojo { public static void main(String[] args) { String version = System.getProperty(“java.version”); System.out.println(“Hello howtodojo|”); System.out.println(“Java Version :” + version); } }


Second, compile the source code using command below.

javac HelloHowtoDojo.java


Third, run the application.

$ java HelloHowtoDojo Hello howtodojo| Java Version :11.0.7


## Summary

In this tutorial we learn how to install Java OpenJDK 11 on Ubuntu 18.04. We learn to install JDK and JRE packages both headless and non-headless.

At the end we learn how to create, compile, and run Java application using Java 11 on Ubuntu 18.04.

## Related Tutorials

  * <span style="font-size: inherit; background-color: initial;"><a href="https://www.howtodojo.com/tag/install-java-8-ubuntu/">Install Java 8 Ubuntu</a></span>

## References

  * <a aria-label="undefined (opens in a new tab)" href="https://docs.oracle.com/en/java/javase/11/" target="_blank" rel="noreferrer noopener">Java 11 Documentation</a>
  * [OpenJDK 11 Website][1]
  * [Java&#xAE; Platform, Standard Edition & Java Development Kit Version 11 API Specification][2]

 [1]: https://openjdk.java.net/projects/jdk/11/
 [2]: https://docs.oracle.com/en/java/javase/11/docs/api/index.html