July 18, 2020 in Tutorial3 minutes
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.
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
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.
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.
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.
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
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.
To install OpenJDK 11 JRE Headless package we can use the command below. You can install JRE headless to run Java application on server.
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
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.