How to Install Java on Ubuntu 20.04
In this guide, we will describe how to install Java on Ubuntu 20.04.
Table of contents
Java is one of the most popular programming languages used to build different kinds of applications and systems. Java runs on all major operating systems and devices. You can find applications developed in Java on your laptop, phone, and game console.
Before You Begin
There are multiple different implementations of Java. OpenJDK and Oracle Java are the two main implementations of Java, with almost no differences between them except that Oracle Java has a few additional commercial features. Oracle Java License permits only non-commercial use of the software, such as personal use and development use.
The default Ubuntu 20.04 repositories include two OpenJDK packages, Java Runtime Environment (JRE) and Java Development Kit (JDK). The JRE consists of the Java virtual machine (JVM), classes, and binaries that allow you to run Java programs. The JDK includes the JRE and development/debugging tools and libraries necessary to build Java applications.
If you are not sure which Java package to install, the general recommendation is to install to the default OpenJDK (JDK 11) version. Some Java-based applications may require a specific version of Java, so you should consult the application documentation.
Installing OpenJDK 11
At the time of writing, Java 11 is the latest long-term supported (LTS) version of Java. It is also the default Java development and runtime in Ubuntu 20.04.
Run the following commands as a user with sudo privileges or root to update the packages index and install the OpenJDK 11 JDK package:
sudo apt update
sudo apt install openjdk-11-jdk
Once the installation is complete, you can verify it by checking the Java version:
The output should look something like this:
openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)