Install Java 17 on Ubuntu 24.04 and Ubuntu 22.04
On Ubuntu 24.04 LTS and 22.04 LTS, OpenJDK 17 sits right in the official package sources. Here is how to install Java 17 without a PPA and set JAVA_HOME correctly.
Do you want to install Java 17 on your Ubuntu 24.04 LTS or Ubuntu 22.04 LTS server? OpenJDK 17 ships in the official Ubuntu repository on both releases, so a separate PPA is no longer needed today.
Prerequisites
You need SSH access with root privileges (or a user with sudo permissions) on a current Ubuntu release. We recommend Ubuntu 24.04 LTS "Noble Numbat" and Ubuntu 22.04 LTS "Jammy Jellyfish". Ubuntu 20.04 LTS reached the end of regular support in May 2025 and should no longer be used in production.
Start by refreshing the package list of your Ubuntu system and installing any pending updates:
apt update && apt upgrade -y
Which Java versions does Ubuntu ship?
Ubuntu keeps all common LTS versions in the default repository, so you are free to pick the version you need (as of July 2026):
| Package | Ubuntu 24.04 LTS | Ubuntu 22.04 LTS |
|---|---|---|
| openjdk-8-jre-headless | 8u492 | 8u492 |
| openjdk-11-jre-headless | 11.0.31 | 11.0.31 |
| openjdk-17-jre-headless | 17.0.19 | 17.0.19 |
| openjdk-21-jre-headless | 21.0.11 | 21.0.11 |
| openjdk-25-jre-headless | 25.0.3 | 25.0.3 |
That is a clear difference from Debian, where OpenJDK 17 is no longer included as of Debian 13. You can check for yourself at any time whether a package is available on your system:
apt-cache policy openjdk-17-jre-headless
Install Java 17 on Ubuntu 24.04 and 22.04
OpenJDK 17 is part of the official package sources. A single command is enough:
apt install openjdk-17-jre-headless -y
The jre-headless variant contains only the runtime environment without graphical libraries, which makes it the lean and appropriate choice for a server, for example for a Minecraft server or a Java web application.
If you also need a compiler because you build applications directly on the server, install the full JDK:
apt install openjdk-17-jdk -y
Verify the installation
Finally, check whether the installation succeeded by querying the installed Java version:
java -version
If the output starts with openjdk version "17, Java 17 is set up correctly and ready to use.
Alternative: use the default version from Ubuntu
If your application does not require one specific Java version but simply needs a current Java, the meta package is the most convenient way. It automatically pulls in the version that your distribution defines as the default:
apt install default-jre-headless -y
| Distribution | Java version via default-jre-headless |
|---|---|
| Ubuntu 24.04 LTS | Java 21 |
| Ubuntu 22.04 LTS | Java 11 |
Please note: this route gives you Java 17 on neither of the two releases. If you explicitly need Java 17, stay with the openjdk-17-jre-headless package.
Set JAVA_HOME
Many Java applications and build systems expect the JAVA_HOME environment variable. On Ubuntu, OpenJDK 17 usually lives in its own directory below /usr/lib/jvm/. This is how you determine the exact path:
update-alternatives --list java
Then add the path permanently to /etc/environment:
JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
After a fresh login over SSH, the variable is available system wide.
Manage several Java versions in parallel
If several JDKs are installed, the alternatives system decides which version starts when you call java. You select the default version you want interactively:
update-alternatives --config java
Alternative: Eclipse Temurin from the Adoptium repository
If you need a specific Java 17 build that receives updates faster than the distribution package, Eclipse Temurin is a good option. Set up the Adoptium repository for it:
apt install -y wget gpg apt-transport-https ca-certificates
mkdir -p /etc/apt/keyrings
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | tee /etc/apt/keyrings/adoptium.asc
echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list
apt update
apt install temurin-17-jre -y
For Ubuntu 24.04 the Adoptium repository provides versions 8 through 26, and the same package source is available for Ubuntu 22.04 as well. If you need a compiler, take temurin-17-jdk. The signing key is stored here as a separate file under /etc/apt/keyrings/ and is assigned to this one repository via signed-by=. The apt-key command that used to be common is deprecated, because a key added that way would be valid for every package source on the system.
Common errors and how to fix them
Guides that use ppa:linuxuprising/java or oracle-java17-installer: This approach dates back to a time when OpenJDK 17 was not yet in the Ubuntu package sources. On Ubuntu 24.04 and 22.04 it is unnecessary, and the official openjdk-17-jre-headless package is the better choice.
"Unable to locate package openjdk-17-jre-headless": The local package list is out of date. Run apt update and try again.
java -version shows a different version: An older Java installation is still set as the default on the system. Correct this with update-alternatives --config java.
Your application does not start even though Java 17 is installed: Some software checks the Java version at startup and requires a specific major version. The application log file usually names the exact version it expects.
Frequently asked questions
Which command installs Java 17 on Ubuntu?
Do I still need the linuxuprising PPA or the oracle-java17-installer?
How do I set JAVA_HOME on Ubuntu?
How do I check whether Java 17 was installed successfully?
What should I do if java -version shows a different version?
2022-2026 KernelHost GmbH. All rights reserved. This guide is protected by copyright. Republishing it on other websites, in whole, in part or in edited form, is not permitted without our written consent. Quoting with a source credit and a link is expressly welcome.

