In this article, I’ll walk you through the installation of Java JDK (Java Development Kit) on an Ubuntu 20.04 Linux system. Java is a popular programming language used for development of Desktop Applications, Games, Mobile applications and many others. Ubuntu 20.04 was released recently and is now ready for Production use. As a Java Developer, you’ll want to install the default Java available on Ubuntu 20.04.

Install Java on Ubuntu 20.04 LTS Linux

We will focus on the installation of the default version of Java on Ubuntu 20.04. You can check available versions with the command:

sudo apt update

Once the APT index is updated, check versions of Java available on the default repositories of Ubuntu:

$ apt policy default-jdk
  Installed: (none)
  Candidate: 2:1.11-72
  Version table:
     2:1.11-72 500
        500 focal/main amd64 Packages

We will install both Java Runtime Environment (JRE) and the Java Development Kit (JDK) on Ubuntu 20.04:

sudo apt install default-jdk default-jre

A number of dependencies will be installed, you can validate and agree to install Java on Ubuntu 20.04 with the y key:

The following NEW packages will be installed:
  at-spi2-core ca-certificates-java default-jdk default-jdk-headless default-jre default-jre-headless fontconfig-config fonts-dejavu-core
  fonts-dejavu-extra java-common libatk-bridge2.0-0 libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0 libatk1.0-data libatspi2.0-0
  libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfontconfig1
  libfontenc1 libgif7 libgl1 libgl1-mesa-dri libglapi-mesa libglvnd0 libglx-mesa0 libglx0 libice-dev libice6 libjpeg-turbo8 libjpeg8 liblcms2-2
  libllvm9 libnspr4 libnss3 libpciaccess0 libpcsclite1 libpthread-stubs0-dev libsensors-config libsensors5 libsm-dev libsm6 libvulkan1
  libwayland-client0 libx11-dev libx11-xcb1 libxau-dev libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-randr0 libxcb-shape0
  libxcb-sync1 libxcb1-dev libxcomposite1 libxdamage1 libxdmcp-dev libxfixes3 libxft2 libxi6 libxinerama1 libxkbfile1 libxmu6 libxpm4 libxrandr2
  libxrender1 libxshmfence1 libxt-dev libxt6 libxtst6 libxv1 libxxf86dga1 libxxf86vm1 mesa-vulkan-drivers openjdk-11-jdk openjdk-11-jdk-headless
  openjdk-11-jre openjdk-11-jre-headless x11-common x11-utils x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev
0 upgraded, 92 newly installed, 0 to remove and 18 not upgraded.
Need to get 296 MB of archives.
After this operation, 794 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Confirm Java installation on Ubuntu 20.04

After successfully installing Java on Ubuntu 20.04, confirm the version with the java command line.

$ java -version
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)

Write a test Java application.

cat > <<HELLO
public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello World!");

Run the test java application created.

$ java
Hello World!

If you have more that one version of Java installed, set default Java to use with the command:

sudo update-alternatives --config java

You must have noted you can directly run Java source files in Java 11. The compilation step is automatically handled for you.

You have successfully installed Java 11 on Ubuntu 20.04 Linux machine.

Recommended Java Books to read:

Best Books for Learning Java Programming