OpenJDK 17 is a free, open-source implementation of the Java Platform used to run and develop Java applications. As a Long-Term Support (LTS) release, it provides the stability and modern language features that developers and enterprises require. This guide covers two installation methods: the Ubuntu default repositories for simplicity, and Eclipse Temurin for enterprise-quality builds with faster security updates. By the end of this guide, you will have OpenJDK 17 installed on Ubuntu with the ability to manage multiple Java versions and verify your installation.
Compare OpenJDK LTS Releases for Ubuntu
Before installing, confirm that OpenJDK 17 matches your project requirements. The table below compares LTS Java versions available in Ubuntu’s default repositories.
| Java Version | LTS Support Until | Choose It When | Trade-offs |
|---|---|---|---|
| OpenJDK 8 | At least December 2030 | 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 |
| OpenJDK 11 | At least October 2027 | Enterprise applications, build servers, projects needing stable LTS with module system support and modern TLS | Lacks Java 21 features; some newer frameworks require 17+ as minimum |
| OpenJDK 17 | At least October 2027 | Spring Boot 3.x, Jakarta EE 10+, or workloads benefiting from records and sealed classes | Missing virtual threads and newer pattern matching features from Java 21 |
| OpenJDK 21 | At least December 2029 | New projects, high-concurrency applications using virtual threads, or development requiring the latest stable LTS features | Newest LTS release; verify all dependencies support Java 21 before migrating production workloads |
Choose OpenJDK 17 when starting new projects, 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 with Java 8 or 11 requirements, consider the corresponding OpenJDK 8 or OpenJDK 11 guides instead.
Choose Your OpenJDK 17 Installation Method
This guide covers two installation methods. The table below compares each approach to help you decide which fits your needs:
| Method | Source | Updates | Best For |
|---|---|---|---|
| Ubuntu APT | Ubuntu Repos | Via apt upgrade | Most users; simpler setup, no external repositories needed |
| Eclipse Temurin | Adoptium | 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 22.04 LTS, 24.04 LTS, and 26.04 LTS. The Eclipse Temurin method currently supports Ubuntu 22.04 and 24.04; Adoptium typically adds support for new Ubuntu releases within a few months of their launch.
Update Ubuntu Before OpenJDK 17 Installation
First, update your Ubuntu system to ensure all packages are current and avoid potential dependency conflicts during installation:
sudo apt update
sudo apt upgrade
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.
Install JRE or JDK
Next, choose the package that matches your needs. If you only need to run Java applications without developing them, install the Java Runtime Environment (JRE):
sudo apt install openjdk-17-jre
Alternatively, if you plan to develop Java applications or use build tools like Apache Maven, install the full Java Development Kit (JDK). This includes the JRE plus development tools such as the Java compiler:
sudo apt install openjdk-17-jdk
The JRE is sufficient for running Java applications, while the JDK is required for development purposes. If unsure, install the JDK since it includes everything in the JRE.
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 | \
gpg --dearmor | sudo tee /usr/share/keyrings/adoptium.gpg > /dev/null
Add the Adoptium Repository
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
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)))
On x86_64 Ubuntu systems with OpenJDK 17 as the active version, this returns:
/usr/lib/jvm/java-17-openjdk-amd64
On ARM64 systems (such as Raspberry Pi or AWS Graviton), the path is
/usr/lib/jvm/java-17-openjdk-arm64instead. Always use thedirnamecommand above to detect the correct path for your architecture.
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
Test the Installation
With the installation complete, verify that Java compiles and runs correctly by creating a simple test program. This step confirms that both the runtime and the compiler are functioning as expected before you start real development work.
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.
Troubleshoot Common Issues
Even with a successful installation, you may encounter issues when working with Java in development environments. The following sections address the most common problems and their solutions.
Wrong Java Version Running
If java --version shows a different version than expected, you likely have multiple Java installations. Check which versions are available:
sudo update-alternatives --config java
Select the correct version number and verify the change took effect. If you also develop Java applications, remember to switch the compiler as well:
sudo update-alternatives --config javac
JAVA_HOME Not Set or Incorrect
Build tools like Maven and Gradle require JAVA_HOME to function. If you receive errors about JAVA_HOME being undefined, first find your 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
Finally, confirm the variable is set correctly:
echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64
Compilation Fails with Version Errors
If compilation fails with messages about unsupported class file versions, your compiler and runtime versions don’t match. Ensure both use the same Java version:
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 earlier in this guide.
Remove OpenJDK 17
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:
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.
Conclusion
You now have OpenJDK 17 installed on Ubuntu and configured as your Java runtime. With the update-alternatives system, you can switch between multiple Java versions as needed for different projects. For Java development workflows, consider installing Apache Maven or Gradle as build tools. If your projects require a different LTS release, explore OpenJDK 21 for newer applications or OpenJDK 8 for legacy systems.
Useful Resources
For additional information about Java releases and downloads, these official resources may help:
- OpenJDK 17 Project Page provides official documentation, specifications, and release information for Java 17.
- Eclipse Adoptium Support Page provides release roadmaps, support timelines, and downloads for enterprise-quality OpenJDK builds.
- Setting the Java Environment Path in Ubuntu covers persistent JAVA_HOME configuration in detail.