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

This tutorial is going to show you how to install Oracle Java 8 and OpenJDK 11 on Ubuntu 22.04/Ubuntu 20.04. Java 11 has been released on September 25, 2018 and it’s the first long term support (LTS) release since Oracle changed release schedule.

Java Release Model

Previously, 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 company management, 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 a LTS release (Long Time Support), which is supported for 8 years, to appease company management. Java 11 is the first LTS release. The next LTS will be Java 17. Java 8 will be receiving updates through 2025. Non-LTS releases will no longer receive update once the next version comes out. That means Java 9 and Java 10 have already been phased out.

OpenJDK vs Oracle JDK

Oracle started providing its own OpenJDK builds since Java 9. Closed-source features of Oracle JDK, 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 license. Oracle’s OpenJDK is released under GPL. If you want commercial support, you can use Oracle JDK, which is released under OTN (Oracle Technology Network) license.

Oracle’s OpenJDK builds are available at There are other distributions of OpenJDK, such as AdoptOpenJDK and Amazon Correcto.

Installing Oracle JDK 8 on Ubuntu 22.04/Ubuntu 20.04

Oracle JDK 8 (aka 1.8) no longer uses BCL (Binary Code License). From April 16, 2019, Oracle JDK 8 uses the OTN (Oracle Technology Network) license, which requires you to create an Oracle account to download JDK 8. So you can not use PPA to install JDK 8 anymore.

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

oracle jdk 8 ubuntu 18.04

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

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

Now we can check Java version.

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


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 Java compiler version

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


javac 1.8.0_221

Installing Oracle’s OpenJDK 11 on Ubuntu 22.04 and Ubuntu 20.04

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

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. Once the installation is complete, check 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)

Setting the Default JDK

First, you need to run the following commands to add JDK 8 to the alternatives 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 1

To set a default JDK on 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 might want to choose JDK 11.

set default jdk ubuntu 18.04

You also need to do the same for Java compiler.

sudo update-alternatives --config javac

Now you can run java -version and javac -version command to check the default JDK.

Wrapping Up

That’s it! 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 useful, then subscribe to our free newsletter to get more tips and tricks.

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

Take care 🙂

Rate this tutorial
[Total: 13 Average: 4.9]

7 Responses to “How To Install Oracle Java 8 and OpenJDK 11 on Ubuntu 22.04, 20.04

  • Gaurav Chaudhary
    5 years ago

    You saved lots of productive hours by providing to the point how to guide. Thanks a lot!!

  • Martin Pohl
    5 years ago


    be aware that Oracle Java is no longer free. It is only free for specific scenarios…


  • Today Jan 12th 2020, instead of using 221 during your installation process used 231.

  • Charlie
    4 years ago

    This really save my day!! Thanks!

  • Excellent tutorial! You have been of great help. Thanks.

  • Really nice article. Totally worth bookmarking for future references

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here