How to Install OpenJDK 17 on Ubuntu 26.04, 24.04 and 22.04

Last updated Wednesday, April 29, 2026 9:11 pm Joshua James 10 min read

Java 17 still anchors many Spring Boot 3.x, Jakarta EE 10, Jenkins, and Gradle workflows, even as newer Java LTS branches are available. If you need to install OpenJDK 17 on Ubuntu 26.04 LTS (Resolute Raccoon), 24.04 LTS (Noble Numbat), or 22.04 LTS (Jammy Jellyfish), Ubuntu’s APT package is the safest default; Eclipse Temurin is useful when your team standardizes on Adoptium’s TCK-tested builds.

Install OpenJDK 17 on Ubuntu

On a clean Ubuntu system, install the full OpenJDK 17 JDK from Ubuntu’s repositories with these commands:

sudo apt update
sudo apt install openjdk-17-jdk

For a headless server, container base image, or CI runner that only needs the runtime, install the headless JRE instead:

sudo apt install openjdk-17-jre-headless

If your scripts still use apt-get, keep the same package name. apt and apt-get target the same Ubuntu package here; the examples below use apt for interactive terminal commands.

The full sections below explain package choices, repository scope, verification, JAVA_HOME, and cleanup before you make changes on a system that already has another Java version installed.

MethodChannelUbuntu ScopeUpdatesBest For
Ubuntu APT (Recommended)Ubuntu repositories26.04, 24.04, and 22.04Via apt upgradeMost users; no external repository needed
Eclipse TemurinAdoptium APT repository24.04 and 22.04 currentlyVia apt upgradeTeams that require Adoptium’s TCK-tested Temurin builds

Choose one method unless you intentionally need side-by-side Java builds. If you install both Ubuntu OpenJDK and Temurin, use update-alternatives to decide which java and javac commands become the default.

The Ubuntu APT method works on Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. The Adoptium APT repository currently has package metadata for Ubuntu 24.04 and 22.04, but not Ubuntu 26.04. Do not point Ubuntu 26.04 at the older noble repository as a normal install path.

OpenJDK 17 Download, Snap, and WSL Scope

If you searched for an OpenJDK 17 download, use Ubuntu APT or the Adoptium APT repository first so updates stay package-managed. Adoptium also publishes Linux tarballs for Temurin 17 on its official Temurin release page, but manual tarball installs need separate PATH, update, and removal handling.

The Snap Store does publish an OpenJDK snap, but it tracks the current JDK line rather than pinned OpenJDK 17. Do not use the Snap package when your project specifically requires Java 17.

Ubuntu running under Windows Subsystem for Linux uses the same APT commands shown here. Command-line Java tools work normally in WSL; graphical Java applications need WSLg on Windows 11 or a separate X server on Windows 10.

Update Ubuntu Before Installing OpenJDK 17

Refresh the package index and upgrade installed packages to avoid dependency conflicts during installation:

sudo apt update
sudo apt upgrade

These commands use sudo for tasks that need root privileges. If your user is not in the sudoers file yet, run the commands as root or follow the guide to add a new user to sudoers on Ubuntu.

The apt update command refreshes the package index, while apt upgrade installs the latest versions of all installed packages.

Method 1: Install OpenJDK 17 via Ubuntu APT (Recommended)

Ubuntu’s default repositories include OpenJDK 17 packages, making installation straightforward without adding external sources. On Ubuntu 26.04 and 22.04, the packages come from the universe component; on Ubuntu 24.04, the current update candidate comes from main. If a minimal system cannot locate the package, the troubleshooting section shows the component check, and the Ubuntu components guide explains how to enable Universe on Ubuntu.

Before installing, you can view the available OpenJDK 17 packages:

apt-cache search openjdk-17

Relevant output includes several package variants:

openjdk-17-jdk - OpenJDK Development Kit (JDK)
openjdk-17-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-17-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-17-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-17-source - OpenJDK Development Kit (JDK) source files
openjdk-17-doc - OpenJDK Development Kit (JDK) documentation
openjdk-17-demo - Java runtime based on OpenJDK (demos and examples)

The “headless” packages exclude graphical libraries and are designed for servers or CI/CD systems without a display. If you are setting up a build server, container image, or any environment without a GUI, choose the headless variants for a smaller installation footprint.

Choose the Right OpenJDK 17 Package

OpenJDK 17 ships several package variants. Use the table below to pick the right one for your use case:

PackageContainsUse When
openjdk-17-jreRuntime onlyRunning Java applications on desktops
openjdk-17-jdkRuntime + compiler + dev toolsDeveloping Java applications, using build tools like Apache Maven on Ubuntu
openjdk-17-jre-headlessRuntime (no GUI libraries)Servers, CI/CD pipelines, containers
openjdk-17-jdk-headlessDev tools (no GUI libraries)Headless build servers, Docker images

Run only the package command that matches your use case. To install the JRE for running Java applications on a desktop system:

sudo apt install openjdk-17-jre

To install the full JDK for development (includes the JRE plus the Java compiler and dev tools):

sudo apt install openjdk-17-jdk

For server or CI workloads that do not need desktop Java libraries, use one of the headless packages instead:

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

If you are unsure, install openjdk-17-jdk. It includes everything in the JRE and covers both running and developing Java applications.

Verify the OpenJDK 17 APT Installation

After installation completes, verify that Java is accessible by checking the installed version:

java --version

Expected output confirming OpenJDK 17 is installed:

openjdk 17.0.18 2026-01-20
OpenJDK Runtime Environment (build 17.0.18+8-Ubuntu-1)
OpenJDK 64-Bit Server VM (build 17.0.18+8-Ubuntu-1, mixed mode, sharing)

If you installed the JDK, also verify the Java compiler is available:

javac --version
javac 17.0.18

Method 2: Install Eclipse Temurin 17 via Adoptium APT

Eclipse Temurin is a production-ready OpenJDK distribution from the Adoptium project. These builds are TCK-tested for Java compatibility and pass the AQAvit verification suite. Use this method on Ubuntu 24.04 or 22.04 when you specifically need Temurin packages from Adoptium’s APT repository.

Ubuntu 26.04 users should use the Ubuntu APT method until Adoptium publishes a resolute repository. The current Adoptium repository has noble and jammy metadata, but a normal install guide should not repoint a newer Ubuntu release to an older suite.

Install Temurin Repository Prerequisites

Install the tools needed to fetch the Adoptium signing key and create the APT source file:

sudo apt install curl gpg

Import the Adoptium GPG Key for Temurin

Download and install the Adoptium repository signing key. The -fsSL flags tell curl to fail on HTTP errors, suppress progress output, and follow redirects, while gpg --dearmor converts the key into the binary keyring format APT expects:

curl -fsSL https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo gpg --dearmor --yes -o /usr/share/keyrings/adoptium.gpg

Add the Adoptium Repository (DEB822)

Create the repository configuration file using the DEB822 format. The command sources your Ubuntu codename from /etc/os-release and writes the detected CPU architecture into the source file:

. /etc/os-release
printf '%s\n' \
  'Types: deb' \
  'URIs: https://packages.adoptium.net/artifactory/deb' \
  "Suites: $VERSION_CODENAME" \
  'Components: main' \
  "Architectures: $(dpkg --print-architecture)" \
  'Signed-By: /usr/share/keyrings/adoptium.gpg' | sudo tee /etc/apt/sources.list.d/adoptium.sources > /dev/null

Verify the file before refreshing APT so a paste error is easy to catch:

cat /etc/apt/sources.list.d/adoptium.sources

After adding the repository, refresh your package index:

sudo apt update

Install Eclipse Temurin 17 via APT

Install the Eclipse Temurin 17 JDK package:

sudo apt install temurin-17-jdk

Adoptium also provides temurin-17-jre if you only need the runtime environment without development tools.

Verify the Temurin 17 Installation

After installation, verify that Temurin is accessible by checking the version:

/usr/lib/jvm/temurin-17-jdk-amd64/bin/java --version
/usr/lib/jvm/temurin-17-jdk-amd64/bin/javac --version

The output should show the Temurin build identifier:

openjdk 17.0.19 2026-04-21
OpenJDK Runtime Environment Temurin-17.0.19+10 (build 17.0.19+10)
OpenJDK 64-Bit Server VM Temurin-17.0.19+10 (build 17.0.19+10, mixed mode, sharing)
javac 17.0.19

If java --version still shows Ubuntu’s OpenJDK build after installing Temurin, both packages are installed and Ubuntu’s alternative selection did not change. Switch the runtime and compiler manually:

sudo update-alternatives --config java
sudo update-alternatives --config javac

Update Temurin 17 to the Latest Version

Temurin receives updates through the Adoptium APT repository. To check for and install the latest version, run:

sudo apt update && sudo apt install --only-upgrade temurin-17-jdk

Because Temurin is package-managed after the repository is configured, a separate updater script is usually unnecessary. Use your normal manual package-maintenance routine unless your environment already has a tested unattended-upgrade policy for third-party APT repositories.

Manage Multiple Java Versions on Ubuntu

If you have multiple Java versions installed on your system, Ubuntu provides the update-alternatives command to switch between them. This is particularly useful when different projects require different Java versions.

Switch the Default Java Runtime on Ubuntu

To view all installed Java versions and select one as the system default, run:

sudo update-alternatives --config java

This command opens an interactive menu listing each installed Java runtime by path. Choose the entry that points to /usr/lib/jvm/java-17-openjdk-amd64/bin/java for Ubuntu OpenJDK on x86_64 systems, or the matching Java 17 path for your architecture or Temurin installation. After making your selection, verify the change with java --version.

Switch the Default Java Compiler on Ubuntu

If you installed multiple JDK versions, you should also switch the Java compiler to match the runtime. Otherwise, you may compile with one version but run with another, causing compatibility issues:

sudo update-alternatives --config javac

Select the same version number you chose for the runtime to keep your development environment consistent.

Set the JAVA_HOME Environment Variable on Ubuntu

Many Java applications and build tools require the JAVA_HOME environment variable to locate your Java installation. For detailed instructions on configuring this variable persistently, see how to set the Java environment path on Ubuntu.

As a quick reference, you can find the path to your active Java installation with:

dirname "$(dirname "$(readlink -f "$(command -v java)")")"

This command chain locates the java binary, resolves any symbolic links to the real file path, then strips two directory levels to return the JVM root directory. The path varies by CPU architecture:

PackageArchitectureJAVA_HOME Path
Ubuntu OpenJDKx86_64 (Intel/AMD)/usr/lib/jvm/java-17-openjdk-amd64
Ubuntu OpenJDKARM64 (Raspberry Pi, AWS Graviton)/usr/lib/jvm/java-17-openjdk-arm64
Eclipse Temurinx86_64 (Intel/AMD)/usr/lib/jvm/temurin-17-jdk-amd64

Always use the dirname command in this section to detect the correct path for your architecture rather than hardcoding it.

To set the active JVM as JAVA_HOME for the current user, replace any older export JAVA_HOME= line in your ~/.bashrc file, append the detected path, and reload the file:

touch "$HOME/.bashrc"
JAVA_HOME_PATH="$(dirname "$(dirname "$(readlink -f "$(command -v java)")")")"
grep -v '^export JAVA_HOME=' "$HOME/.bashrc" > "$HOME/.bashrc.tmp" || true
printf 'export JAVA_HOME=%s\n' "$JAVA_HOME_PATH" >> "$HOME/.bashrc.tmp"
mv "$HOME/.bashrc.tmp" "$HOME/.bashrc"
. "$HOME/.bashrc"

Verify the variable is set correctly:

echo "$JAVA_HOME"
/usr/lib/jvm/java-17-openjdk-amd64

Opening a new terminal window also applies the changes without running source.

Test Your OpenJDK 17 Installation on Ubuntu

With the installation complete, verify that Java compiles and runs correctly by creating a simple test program. This confirms that both the runtime and the compiler work before you start real development.

Create a Java Test Program

Create a new Java source file using your preferred text editor:

nano Hello.java

Add the following Java code to the file:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello from OpenJDK 17!");
        System.out.println("Java feature version: " + Runtime.version().feature());
    }
}

Save the file with Ctrl+O and exit nano with Ctrl+X.

Compile and Run the Java Program

Compile the Java source code into bytecode:

javac Hello.java

If compilation succeeds without errors, a Hello.class file appears in the current directory. Run the compiled program with:

java Hello

Expected output:

Hello from OpenJDK 17!
Java feature version: 17

This output confirms OpenJDK 17 compiles and runs Java source code correctly.

Compare OpenJDK LTS Releases for Ubuntu

If you are unsure whether OpenJDK 17 is the right version for your project, the table below compares common LTS Java branches. For official Java 17 specifications and release details, see the OpenJDK 17 Project Page. For current Eclipse Temurin availability windows, see the Adoptium support roadmap.

Java VersionTemurin AvailabilityChoose It WhenTrade-offs
OpenJDK 25At least September 2031New projects that can target the latest Java LTS branchNewest LTS release; verify framework compatibility before production migration
OpenJDK 21At least December 2029High-concurrency applications using virtual threads or modern Java runtime featuresSome frameworks and enterprise baselines still standardize on Java 17
OpenJDK 17At least October 2027Spring Boot 3.x, Jakarta EE 10+, or workloads benefiting from records and sealed classesLacks virtual threads and newer language/runtime features from Java 21 and 25
OpenJDK 11At least October 2027Enterprise applications, build servers, projects needing stable LTS with module system support and modern TLSSome newer frameworks require Java 17 or later as the minimum
OpenJDK 8At least December 2030Legacy applications, older frameworks like Spring 4.x, or vendor-certified deployments requiring Java 8Missing modern language features such as records, sealed classes, and virtual threads

Choose OpenJDK 17 when your frameworks require Java 17 as a minimum (Spring Boot 3.x, Jakarta EE 10+), or when you want access to modern language features like records, sealed classes, and pattern matching. For legacy applications, consider OpenJDK 8 or OpenJDK 11 instead.

Troubleshoot OpenJDK 17 Issues on Ubuntu

The sections below address the most common OpenJDK 17 problems on Ubuntu with their error messages and solutions.

Fix Wrong Java Version on Ubuntu

If java --version reports a different version than expected, you likely have multiple Java installations. For example, you may see Java 11 instead of 17:

openjdk 11.0.x 20xx-xx-xx
OpenJDK Runtime Environment (build 11.0.x+x-Ubuntu-x)

Check which versions are available and switch to OpenJDK 17:

sudo update-alternatives --config java

Select the entry pointing to java-17-openjdk and verify with java --version. If you develop Java applications, also switch the compiler:

sudo update-alternatives --config javac

Fix JAVA_HOME Not Set or Incorrect on Ubuntu

Build tools like Maven and Gradle require JAVA_HOME to function. If the variable is missing or points to the wrong path, you may see errors like:

Error: JAVA_HOME is not defined correctly.
  We cannot execute /usr/lib/jvm/java-11-openjdk-amd64/bin/java

Find your active Java installation path:

dirname "$(dirname "$(readlink -f "$(command -v java)")")"

Then replace any stale JAVA_HOME export in your shell configuration and reload it:

touch "$HOME/.bashrc"
JAVA_HOME_PATH="$(dirname "$(dirname "$(readlink -f "$(command -v java)")")")"
grep -v '^export JAVA_HOME=' "$HOME/.bashrc" > "$HOME/.bashrc.tmp" || true
printf 'export JAVA_HOME=%s\n' "$JAVA_HOME_PATH" >> "$HOME/.bashrc.tmp"
mv "$HOME/.bashrc.tmp" "$HOME/.bashrc"
. "$HOME/.bashrc"

Confirm the variable is set correctly:

echo "$JAVA_HOME"
/usr/lib/jvm/java-17-openjdk-amd64

Fix Java Compilation Version Errors

If you compile with one Java version but run with another, you may see an UnsupportedClassVersionError like:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Hello has been
compiled by a more recent version of the Java Runtime (class file version 61.0),
this version of the Java Runtime only recognizes class file versions up to 55.0

This means your compiler (javac) and runtime (java) are mismatched. Check both versions:

java --version
javac --version

Both commands should report the same major version number (17). If they differ, use sudo update-alternatives --config java and sudo update-alternatives --config javac to align the runtime and compiler.

Fix “Unable to Locate Package openjdk-17-jdk” on Ubuntu

If APT reports E: Unable to locate package openjdk-17-jdk or has no installation candidate, your package index is outdated or the universe repository component is disabled. On Ubuntu 22.04 and 26.04, OpenJDK 17 ships in the universe component rather than main:

sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update

After enabling the repository component and refreshing the package index, confirm the package is visible:

apt-cache policy openjdk-17-jdk

The output should show a candidate version instead of Candidate: (none). On Ubuntu 26.04 and 22.04, the repository line should include universe; on Ubuntu 24.04, the current update candidate comes from main. With a valid candidate listed, retry sudo apt install openjdk-17-jdk to complete the installation.

Remove OpenJDK 17 from Ubuntu

If you no longer need OpenJDK 17, use the appropriate removal command based on which installation method you used.

Remove Ubuntu APT OpenJDK 17

To remove the OpenJDK 17 packages installed from Ubuntu’s default repositories:

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

Preview dependency cleanup before removing automatically installed packages:

sudo apt autoremove --dry-run

If the preview only lists Java-related packages you no longer need, run the real cleanup:

sudo apt autoremove

Remove Eclipse Temurin 17

To remove Eclipse Temurin 17 installed from the Adoptium repository:

sudo apt remove temurin-17-jdk

Then preview and run dependency cleanup only if the listed packages are safe to remove:

sudo apt autoremove --dry-run
sudo apt autoremove

Optionally, remove the Adoptium CA package, repository, and GPG key if you no longer need any Temurin packages:

The following commands permanently delete the repository support package, source configuration, and signing key. Only run them if you do not plan to install any other Temurin packages from Adoptium.

sudo apt purge adoptium-ca-certificates
sudo rm -f /etc/apt/sources.list.d/adoptium.sources
sudo rm -f /usr/share/keyrings/adoptium.gpg
sudo apt update

Verify OpenJDK 17 Removal

After removal, verify package state directly. This check reports any OpenJDK 17 packages still installed from Ubuntu’s repositories:

dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' openjdk-17-jdk openjdk-17-jre openjdk-17-jdk-headless openjdk-17-jre-headless 2>/dev/null | grep '^ii' || echo "No Ubuntu OpenJDK 17 packages are installed."

Expected output after removing the Ubuntu APT packages:

No Ubuntu OpenJDK 17 packages are installed.

If you removed Temurin instead, check its package state separately:

dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' temurin-17-jdk 2>/dev/null | grep '^ii' || echo "Temurin 17 is not installed."

If JAVA_HOME still points to the removed Java directory, replace it with the active Java path or remove the line from ~/.bashrc. Otherwise, Maven, Gradle, or application launch scripts can fail even after the package removal succeeds.

Conclusion

OpenJDK 17 is running on Ubuntu with update-alternatives available when projects need different Java runtimes. For build automation, add Apache Maven on Ubuntu; for newer runtime features such as virtual threads, compare OpenJDK 21 on Ubuntu.

Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffee Buy me a coffee

Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: