How To Install Oracle Java 8 and OpenJDK 11 on Ubuntu 22.04, 20.04

This tutorial will show you how to install Oracle Java 8 and OpenJDK 11 on Ubuntu 22.04/Ubuntu 20.04. Java 11 was released on September 25, 2018 and is the first Long Term Support (LTS) release since Oracle changed the release schedule.


Release Model


Oracle releases a new major version of Java every two years, a minor version every 6 months. (It took 3 years to release Java 9, because of Jigsaw.) Some people, often the management of the company, like this model because it makes production stable. Other people, often developers, think this is too slow. They like innovations.

After Java 9, Oracle releases a new major version of Java every 6 months to make developers happy. Every 3 years, there will be an LTS (Long Time Support) version, which is supported for 8 years, to appease the administration of the company. Java 11 is the first LTS release. The next LTS will be Java 17. Java 8 will receive updates until 2025. Non-LTS versions will no longer receive updates once the next version is released. That means Java 9 and Java 10 have already been removed.

OpenJDK vs Oracle JDK Oracle

started providing its own OpenJDK builds from Java 9. Oracle JDK closed-source features such as Java Flight Recorder and Java Mission Control are pushed to OpenJDK. Starting with Java 11, Oracle JDK and Oracle’s OpenJDK builds are now functionally identical and interchangeable. The differences between the two are cosmetic, packaging, and licensing. Oracle’s OpenJDK is released under the GPL. If you want commercial support, you can use Oracle JDK, which is released under OTN (Oracle Technology Network) license.

Oracle OpenJDK builds are available in There are other OpenJDK distributions, such as AdoptOpenJDK and Amazon Correct.

Installing Oracle JDK 8

on Ubuntu 22.04 / Ubuntu 20.04 Oracle JDK

8 (

also known as 1.8) no longer uses BCL (Binary Code License). As of April 16, 2019, Oracle JDK 8 uses the Oracle Technology Network (OTN) license, which requires you to create an Oracle account to download JDK 8. Therefore, you can no longer use PPA to install JDK 8.

Go to the Oracle JDK 8 download page. Accept the license agreement and download the tar.gz file. It will prompt you to create an Oracle account.

<img src="" alt="Oracle JDK 8

Ubuntu 18.04″ />

After logging into your Oracle account, you can download JDK 8. Then open a terminal window and navigate to the download directory. Then extract the tar.gz file to the /usr/lib/jvm/ directory.

sudo tar xvf jdk-8u221-linux-x64.tar.gz -directory /usr/lib/jvm/

Now we can check

the Java version. /usr/lib/jvm/jdk1.8.0_221/bin/java -version Output: java version “1.8.0_221” Java(TM) SE Runtime Environment (build 1.8.0_221-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)

Check the Java compiler

version /usr/lib/jvm/jdk1.8.0_221/bin/javac -version


javac 1.8.0_221 Installing Oracle OpenJDK 11

on Ubuntu 22.04 and Ubuntu 20.04

Since the OpenJDK 11 build

Oracle’s has the same features as Oracle JDK 11, you can use OpenJDK if you don’t need Oracle’s commercial support. It is strongly recommended that you use your system’s OpenJDK package and package manager for better integration and ease of updating.

Run the following command to install OpenJDK 11 on Ubuntu 22.04 and Ubuntu 20.04 from the default repository.

sudo apt install openjdk-11-jdk

This will also install the openjdk-11-jre package, which contains the Java runtime environment and is required to run Java programs. After the installation is complete, check the version number.

java -version


openjdk 11.0.4 2019-07-16 OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu220.04) OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu220.04, mixed mode, sharing) Default JDK settings

First, you need to run the following commands to add JDK 8 to the alternate system.

sudo update-alternatives -install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_221/bin/java 1 sudo update-alternatives -install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_221/bin/javac


To set a default JDK to Ubuntu 22.04/20.04, run the following command:

sudo update-alternatives -config java

The available options will be listed. Type a number to select a default JDK. JDK 11 has significant stability, functionality, and performance improvements compared to JDK 8, so you may want to choose JDK 11.

set default jdk ubuntu 18.04

You should also do the same for the Java compiler

. sudo update-alternatives -config javac

You can now run java -version and javac -version to check the default JDK.


That’s all! I hope this tutorial helped you install Oracle JDK 8 and OpenJDK 11 on Ubuntu 22.04/20.04. As always, if you found this post helpful, sign up for our free newsletter for more tips and tricks.

You may also want to learn how to identify bugs in your code.

  • How to Proactively Identify Errors in Your Code

Be careful 🙂