This guide walks you through how to install OpenJDK 17 on Ubuntu using two methods: the default Ubuntu APT repositories for a quick setup, and Eclipse Temurin from Adoptium for enterprise-quality, TCK-certified builds. OpenJDK 17 is a Long-Term Support (LTS) release of the Java Platform, first released in September 2021, providing modern language features like records, sealed classes, and pattern matching with community support through September 2029. By the end of this guide, you will have a working Java 17 environment with the ability to manage multiple versions and compile your first program.
Install OpenJDK 17 on Ubuntu
Two installation methods are covered in this guide. The table below compares each approach to help you choose the right one:
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| Ubuntu APT (Recommended) | Ubuntu Repos | 17.0.x | Via apt upgrade | Most users; simpler setup, no external repositories needed |
| Eclipse Temurin | Adoptium | 17.0.x | Via apt upgrade | Enterprise environments; AQAvit-verified builds with faster security patches |
For most users, the Ubuntu APT method provides a well-maintained OpenJDK build that receives regular security updates. If you require builds that are TCK-certified and AQAvit-verified with potentially faster security patch releases, choose the Eclipse Temurin method.
The Ubuntu APT method works identically on Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. The Eclipse Temurin method currently supports Ubuntu 24.04 and 22.04; Adoptium typically adds support for new Ubuntu releases within a few months of their launch.
Update Ubuntu Before Installing OpenJDK 17
First, update your Ubuntu system to ensure all packages are current and avoid potential dependency conflicts during installation:
sudo apt update
sudo apt upgrade
This guide uses
sudofor commands that need root privileges. If your user is not in the sudoers file yet, run the commands as root or follow the guide on how to add a new user to sudoers on Ubuntu.
The apt update command refreshes your package index, while apt upgrade installs the latest versions of all installed packages. Depending on how many packages require updates, this process may take a few minutes.
Method 1: Install OpenJDK 17 via Ubuntu APT (Recommended)
Ubuntu’s default repositories include OpenJDK 17 packages, making installation straightforward without adding external sources. Before installing, you can view the available OpenJDK 17 packages:
apt-cache search openjdk-17
This command displays all packages related to OpenJDK 17. The 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:
| Package | Contains | Use When |
|---|---|---|
openjdk-17-jre | Runtime only | Running Java applications on desktops |
openjdk-17-jdk | Runtime + compiler + dev tools | Developing Java applications, using build tools like Apache Maven |
openjdk-17-jre-headless | Runtime (no GUI libraries) | Servers, CI/CD pipelines, containers |
openjdk-17-jdk-headless | Dev tools (no GUI libraries) | Headless build servers, Docker images |
To install the JRE for running Java applications:
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
If you are unsure, install
openjdk-17-jdk. It includes everything in the JRE and covers both running and developing Java applications.
Verify the Installation
After installation completes, verify that Java is accessible by checking the installed version:
java --version
You should see output confirming OpenJDK 17 is installed:
openjdk 17.0.x 20xx-xx-xx OpenJDK Runtime Environment (build 17.0.x+x-Ubuntu-x) OpenJDK 64-Bit Server VM (build 17.0.x+x-Ubuntu-x, mixed mode, sharing)
If you installed the JDK, also verify the Java compiler is available:
javac --version
javac 17.0.x
Method 2: Install Eclipse Temurin 17 via Adoptium APT
Eclipse Temurin is an enterprise-quality OpenJDK distribution from the Adoptium project. These builds are TCK-certified for Java compatibility and pass the AQAvit verification suite. This method adds the Adoptium APT repository to receive automatic updates.
Import the Adoptium GPG Key
First, download and install the Adoptium repository signing key. This key verifies that packages come from the official Adoptium infrastructure:
wget -qO- https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo gpg --dearmor -o /usr/share/keyrings/adoptium.gpg
Add the Adoptium Repository (DEB822)
Next, create the repository configuration file using the DEB822 format. This script automatically detects your Ubuntu codename and architecture:
cat <<EOF | sudo tee /etc/apt/sources.list.d/adoptium.sources
Types: deb
URIs: https://packages.adoptium.net/artifactory/deb
Suites: $(. /etc/os-release && echo $VERSION_CODENAME)
Components: main
Architectures: $(dpkg --print-architecture)
Signed-By: /usr/share/keyrings/adoptium.gpg
EOF
After adding the repository, refresh your package index:
sudo apt update
Install Temurin 17
Now install the Eclipse Temurin 17 JDK package:
sudo apt install temurin-17-jdk
Adoptium also provides
temurin-17-jreif you only need the runtime environment without development tools.
Verify the Temurin Installation
After installation, verify that Temurin is accessible by checking the version:
java --version
The output should show the Temurin build identifier:
openjdk 17.0.x 2025-xx-xx OpenJDK Runtime Environment Temurin-17.0.x+x (build 17.0.x+x) OpenJDK 64-Bit Server VM Temurin-17.0.x+x (build 17.0.x+x, mixed mode, sharing)
Update Temurin 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
For automated update scripts, use the following bash pattern that checks whether an update is available before attempting the upgrade:
#!/bin/bash
# Update Temurin 17 if a newer version is available
sudo apt update
if apt list --upgradable 2>/dev/null | grep -q temurin-17-jdk; then
echo "Temurin 17 update available, installing..."
sudo apt install --only-upgrade temurin-17-jdk -y
else
echo "Temurin 17 is already at the latest version."
fi
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
To view all installed Java versions and select one as the system default, run:
sudo update-alternatives --config java
This command displays an interactive menu showing all available Java installations with their paths and priorities:
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode Press <enter> to keep the current choice[*], or type selection number:
Enter the selection number corresponding to your desired Java version and press Enter. After making your selection, verify the change with java --version.
Switch the Default Java Compiler
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
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 our guide on setting the Java environment path in Ubuntu.
As a quick reference, you can find the path to your active Java installation with:
dirname $(dirname $(readlink -f $(which java)))
The path varies by CPU architecture. Use the table below to identify the correct value for your system:
| Architecture | JAVA_HOME Path |
|---|---|
| x86_64 (Intel/AMD) | /usr/lib/jvm/java-17-openjdk-amd64 |
| ARM64 (Raspberry Pi, AWS Graviton) | /usr/lib/jvm/java-17-openjdk-arm64 |
Always use the
dirnamecommand above to detect the correct path for your architecture rather than hardcoding it.
To set this as your JAVA_HOME for the current user, add the following to your ~/.bashrc file:
echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64' >> ~/.bashrc
source ~/.bashrc
Verify the variable is set correctly:
echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64
Alternatively, open a new terminal window for the changes to take effect automatically.
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 Test Program
Create a new Java source file using your preferred text editor:
nano Hello.java
Next, 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 version: " + System.getProperty("java.version"));
}
}
Save and close the file when finished.
Compile and Run
Now, 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 version: 17.0.x
This output confirms your OpenJDK 17 installation is working 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 all LTS Java releases available on Ubuntu. For official specifications and release details, see the OpenJDK 17 Project Page.
| Java Version | LTS Support Until | Choose It When | Trade-offs |
|---|---|---|---|
| OpenJDK 25 | September 2033 (community) | New projects, applications requiring finalized scoped values, key derivation APIs, or the latest stable LTS features | Newest LTS release; verify framework compatibility before production migration |
| OpenJDK 21 | September 2031 (community) | High-concurrency applications using virtual threads, projects needing structured concurrency | Scoped values still in preview; missing finalized features from Java 25 |
| OpenJDK 17 | September 2029 (community) | Spring Boot 3.x, Jakarta EE 10+, or workloads benefiting from records and sealed classes | Lacks virtual threads and scoped values from newer releases |
| OpenJDK 11 | September 2027 (community) | Enterprise applications, build servers, projects needing stable LTS with module system support and modern TLS | Lacks Java 25 features; some newer frameworks require 17+ as minimum |
| OpenJDK 8 | December 2030 (community) | Legacy applications, older frameworks like Spring 4.x, or vendor-certified deployments requiring Java 8 | Missing modern language features (no var, no records, no virtual threads); some libraries dropping Java 8 support |
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
Even with a successful installation, you may encounter issues when working with Java in development environments. The following sections address the most common problems with their error messages, causes, and solutions.
Wrong Java Version Running
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
JAVA_HOME Not Set or Incorrect
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
First, find your active Java installation path:
dirname $(dirname $(readlink -f $(which java)))
Then add the result to your shell configuration and reload it:
echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64' >> ~/.bashrc
source ~/.bashrc
Confirm the variable is set correctly:
echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64
Compilation Fails with 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 update-alternatives to align them as described in the multiple versions section above.
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
To remove the OpenJDK 17 packages installed from Ubuntu’s default repositories:
sudo apt remove openjdk-17-jdk openjdk-17-jre
sudo apt autoremove
Remove Eclipse Temurin
To remove Eclipse Temurin 17 installed from the Adoptium repository:
sudo apt remove temurin-17-jdk
sudo apt autoremove
Optionally, remove the Adoptium repository and GPG key if you no longer need any Temurin packages:
The following commands permanently delete the repository configuration and signing key. Only run them if you do not plan to install any other Temurin packages from Adoptium.
sudo rm /etc/apt/sources.list.d/adoptium.sources
sudo rm /usr/share/keyrings/adoptium.gpg
sudo apt update
Verify Removal
After removal, verify that Java is no longer available or has switched to another installed version:
java --version
If no other Java versions are installed, this command returns an error confirming removal:
bash: java: command not found
If another Java version remains installed, the output shows which version is now active. In that case, no further action is needed unless you want to remove all Java installations.
If you previously set
JAVA_HOMEin your~/.bashrcfile, either remove that line or update it to point to a different Java version. Otherwise, applications that rely onJAVA_HOMEwill fail with “directory not found” errors.
OpenJDK is the free, open-source reference implementation of the Java Platform. Oracle JDK is a commercial distribution built from the same source with Oracle’s licensing terms. Since Java 17, both produce functionally identical builds. The main difference is the license and support model: OpenJDK is free for all use, while Oracle JDK requires a paid subscription for production use beyond the free tier.
Yes. OpenJDK 17 is a Long-Term Support release with community support through September 2029. Ubuntu’s default repositories continue to receive security patches, and Eclipse Temurin from Adoptium provides additional enterprise-grade update cycles.
Install the JRE (openjdk-17-jre) if you only need to run Java applications. Install the JDK (openjdk-17-jdk) if you plan to develop Java applications or use build tools like Maven or Gradle. The JDK includes the JRE plus the compiler and development utilities, so installing the JDK covers both use cases.
Eclipse Temurin is an OpenJDK distribution produced by the Adoptium project. It uses the same OpenJDK source code but provides TCK-certified, AQAvit-verified builds with potentially faster security patch releases. Ubuntu’s default OpenJDK packages follow Ubuntu’s own release and security update schedule. Both are free and open-source.
Java 17, released in September 2021, introduced sealed classes for restricted type hierarchies, pattern matching for switch (preview), enhanced pseudo-random number generators, and stronger encapsulation of JDK internals. It also deprecated the Applet API and Security Manager for removal. As an LTS release, Java 17 includes all features from Java 12 through 16, such as records, text blocks, and pattern matching for instanceof.
Conclusion
You now have OpenJDK 17 installed on Ubuntu and configured as your Java runtime. With update-alternatives, you can switch between multiple Java versions as your projects require. For Java development workflows, consider installing Apache Maven as a build tool. If your projects need a different LTS release, explore OpenJDK 21 for virtual threads or OpenJDK 25 for the latest stable features.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags:
<code>command</code>command<pre>block of code</pre><strong>bold</strong><em>italic</em><a href="URL">link</a><blockquote>quote</blockquote>