How To Install JDK on Ubuntu


By Mayuri Fakirpure

Updated on Feb 10, 2024

In this tutorial, we'll explain how to install JDK on Ubuntu Java Development Kit. We will cover Installation of Oracle JDK as well as OpenJDK. 


  • A Ubuntu installed system.
  • User with administrative privileges. 
  • Basic Linux command knowledge.


Before we proceeding with the installation, let us brifly explain the difference between JDK and JRE.


JDK stands for Java Development Kit. It is basically used for Java application development and applets. It contains Java Runtime Environment(JRE) and other development tools like an interpreter, compiler, archiver, and a document generator. If we want to test our Java application on different version of JDK, we can install different version of JDK on the same system and test it.


JRE stands for Java Runtime Environment. It is for running the Java application. It implements Java Virtual Machine(JVM). JVM is the heart of Java programming and provides platform independence. JRE doesn't doen't contain any development tools like interpreter, compiler, or debugger, etc. It is usable if we want to run only Java application and not develop the application.

So as per our requirement, we can install either JDK or JRE. For this demonstration purpose, we are installing JDK 21 but feel free to install JRE with any version you want.

Update Packages

First, Keep the system up-to-date to make sure that we have the latest version of the repository listing.

sudo apt update

There are two ways to install Java on Ubuntu. Oracle JDK and OpenJDK. Both are the same build. The main difference is OpenJDK is an open source project that is maintained by Oracle, Redhat, and the community. Oracle JDK is required commercial license and it is maintained by Oracle. Result of that some features aren't availble with OpenJDK. But OpenJDK works very well. From JDK 17, binaries are free to use in production at no cost. You can check the official website to learn more about it. Visit Oracle JDK official website and OpenJDK official website.

1. Install Oracle JDK

To install Oracle JDK, we need to download it from Oracle official website it doesn't allow automatic installation through package manager. Here yo ucan find Linux based installer files. Download x64 Debian Package

Currently, there are 2 LTS version available JDK 21 and JDK 17. You can download as per your requirements. For this demostration purpose, we are installing JDK 21 which is latest version.

Execute following command to download JDK 21:


Once the download gets completed, install it using dpkg command:

sudo dpkg -i jdk-21_linux-x64_bin.deb

verify the installation by checking the version:

java --version

This command should display information about the installed Java version.

java 21.0.2 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 21.0.2+13-LTS-58)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode, sharing)

We have successfully installed Oracle JDK 21.

2. Install OpenJDK

Ubuntu repositories typically include OpenJDK. It is an open-source implementation of the Java Platform. We can install default version of the JDK which is 11 or we can install the specific version. At the moment 17 TLS version available in the repository. If you want 21 LTS, execute this command: apt install openjdk-21-jdk If the command works for your, it will install 21 LTS version, otherwise install 21 LTS version by Oracle JDK as show above.

For this demostration purpose, we are installing JDK 17. If you have any specific version requirement, replace 17 from following command with your version.

apt install openjdk-17-jdk

After the installation is complete, we can verify that Java has been installed correctly by checking the version:

java --version

This command should display information about the installed Java version.

openjdk 17.0.9 2023-10-17
OpenJDK Runtime Environment (build 17.0.9+9-Ubuntu-122.04)
OpenJDK 64-Bit Server VM (build 17.0.9+9-Ubuntu-122.04, mixed mode, sharing)

We have successfully installed OpenJDK 21.

We have seen how to install Java on Ubuntu 22.04. We have learnt about OpenJDK and OpenJDK. Also the difference between JDK and JRE.

This chapter is completed succesfully.