How to Install OpenJDK 17 on Ubuntu 24.04, 22.04 or 20.04

JDK 17, the open-source reference implementation of Java SE Platform version 17, was finalized through the Java Community Process under JSR 390. Officially available since 14 September 2021, it provides production-ready binaries under the GPL license from Oracle, with other vendors expected to release their binaries soon after. The development and features of JDK 17 were meticulously planned and tracked through the JEP Process, updated by JEP 2.0, and the release itself followed the guidelines of the JDK Release Process (JEP 3).

Key notes of the JDK 17 Release were:

  • JEP 306: Restore Always-Strict Floating-Point Semantics
    • Ensures that all floating-point operations strictly adhere to IEEE 754 standards.
  • JEP 356: Enhanced Pseudo-Random Number Generators
    • Provides new interfaces and implementations for random number generators, improving flexibility and performance.
  • JEP 382: New macOS Rendering Pipeline
    • Introduces a new rendering pipeline for macOS, using the Apple Metal framework to replace the deprecated OpenGL API.
  • JEP 391: macOS/AArch64 Port
    • Adds support for the macOS/AArch64 platform, enabling JDK to run on Apple’s new ARM-based Macs.
  • JEP 398: Deprecate the Applet API for Removal
    • Marks the Applet API for future removal, as it is outdated and largely unused in modern development.
  • JEP 403: Strongly Encapsulate JDK Internals
    • Enhances the security and integrity of the JDK by strongly encapsulating internal APIs.
  • JEP 406: Pattern Matching for switch (Preview)
    • Introduces pattern matching for the switch statement, allowing more concise and readable code.
  • JEP 407: Remove RMI Activation
    • Removes the RMI Activation mechanism, simplifying the RMI stack.
  • JEP 409: Sealed Classes
    • Allows the declaration of sealed classes and interfaces, which restrict which other classes or interfaces may extend or implement them.
  • JEP 410: Remove the Experimental AOT and JIT Compiler
    • Removes the experimental ahead-of-time (AOT) and just-in-time (JIT) compiler features, which were not widely adopted.
  • JEP 411: Deprecate the Security Manager for Removal
    • Marks the Security Manager for future removal, as it has been replaced by more modern security practices.
  • JEP 412: Foreign Function & Memory API (Incubator)
    • Introduces an incubating API for foreign function and memory access, which allows Java programs to interoperate with code and data outside the Java runtime.
  • JEP 414: Vector API (Second Incubator)
    • Provides an API for expressing vector computations that reliably compile to optimal vector instructions on supported CPU architectures.
  • JEP 415: Context-Specific Deserialization Filters
    • Enhances security by allowing the specification of context-specific deserialization filters.

JDK 17 is a long-term support (LTS) release, ensuring extended support and stability for enterprise use. The guide will now demonstrate two different methods to install OpenJDK 17 on Ubuntu, with the recommended method of using Ubuntu’s default repository.

Update Ubuntu before OpenJDK 17 Installation

Before installing OpenJDK, updating Ubuntu to ensure all system packages are current with the “apt update” command is essential. This helps to prevent any potential conflicts during the installation process. To update your Ubuntu system, run the following command in your terminal:

sudo apt update
sudo apt upgrade

Select OpenJDK Installation Method

Install OpenJDK 17 with Ubuntu Repository

The first and most recommended method for installing OpenJDK is through the default Ubuntu repository. You can search for available packages using the “grep” command. To do this, run the following command in your terminal:

apt-cache search openjdk | grep openjdk-17

Example output:

Depending on your version of Ubuntu, you may be able to install OpenJDK 17 JDE and JRE using the following command. This is only applicable if these packages are available in your distribution:

sudo apt install openjdk-17-jre
sudo apt install openjdk-17-jdk

Confirm the installation by running the following command.

java --version

Updates are handled with the standard apt update and upgrade commands. However, you can remove them separately or altogether if you no longer require JDK or JRE.


sudo apt remove openjdk-17-jre openjdk-17-jdk --purge

Note that this will remove any unrequited leftover dependencies and thoroughly wipe the installation and data from your system as much as possible.

Method 2: Install OpenJDK 17 Manual Method

The second method for installing OpenJDK 17 is downloading the .tar.gz archive package. While this option is often more up-to-date than the version in the Ubuntu repository, it requires more manual maintenance, as you’ll need to monitor new updates and repeat the installation process.

Visit the downloads page to obtain the latest build version link. Then, use the following wget command to download the package.

Here’s an example of downloading OpenJDK 17 version 17.0.2 for x64 (however, it is recommended to obtain a new link from the downloads page rather than copying this example):


Note: Remember, the above link is an example, so ensure you grab the latest build version.

Once the download process is complete, the archive will be extracted.

tar -xvf openjdk-17.*

Next, navigate to the directory.

cd <directory_name>

Run the following command to install the OpenJDK 17 files.

sudo mkdir -p /usr/local/openjdk-17
sudo mv * /usr/local/openjdk-17

The next step is to set up the environment variables by adding the following lines to your .bashrc or .bash_profile file.

export JAVA_HOME=/usr/local/openjdk-17
export PATH=$JAVA_HOME/bin:$PATH

Source the .bashrc or .bash_profile file to apply the changes.

source ~/.bashrc

To verify that the installation was successful, run the following command.

java --version

If installed correctly, you should see the following output:

As demonstrated, the version displayed is the latest OpenJDK 17 build.

Switching Alternative Java Versions

After installing Java, you may want to check for newer versions and switch to them if necessary. To do this, use the following command to list the available alternatives:

sudo update-alternatives --config java

Example output:

The previous output shows that Java 11 is listed with “1”. To switch to this version, type the following and press the enter key, and you should see a similar printout:

update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode

Once the switch is complete, you can verify the default version using the following command.

java --version

Example output:

To switch to any other installed versions, repeat the same process.


In conclusion, installing OpenJDK 17 on Ubuntu is straightforward and can be accomplished using several methods. Whether you use the default Ubuntu repository, download the .tar.gz archive package, or switch to a different version, the steps outlined in this article will help you successfully install and manage OpenJDK 17 on your Ubuntu system.

Useful Links

Here are some valuable links related to using OpenJDK 17 on an Ubuntu system:

  • OpenJDK 17 Project: Visit the OpenJDK 17 project page for detailed information about the JDK 17 release, features, and updates.
  • OpenJDK Wiki: Access the OpenJDK Wiki for comprehensive documentation, development guides, and community resources.
  • OpenJDK Downloads: Visit the OpenJDK download page to get the latest builds of JDK 17 and other versions.

These links provide additional information and resources to help you effectively use OpenJDK 17 on your Ubuntu system.

Joshua James
Follow me
Latest posts by Joshua James (see all)