Installing Java 8 and Java 11 on Ubuntu 24.04 and 22.04
Java 8 and Java 11 are still part of the official package sources on Ubuntu 24.04 LTS and 22.04 LTS. Here is how to install the version you need and set it as the default.
Do you want to install Java 8 or Java 11 on your Ubuntu 24.04 LTS or Ubuntu 22.04 LTS server? Good news: unlike Debian, Ubuntu still ships both versions in its official package sources. That makes the installation a matter of minutes.
Prerequisites
You need SSH access with root privileges (or a user with sudo permission) on a current Ubuntu system. 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.
First, refresh the package list on your Ubuntu system and apply any pending updates:
apt update && apt upgrade -y
Which Java versions does Ubuntu ship?
Ubuntu is considerably more generous with Java than Debian and keeps every common LTS release in the standard repository (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 |
For Java 8 and Java 11 on Ubuntu you therefore need neither a PPA nor a third-party source. You can check whether a package is available on your system at any time:
apt-cache policy openjdk-8-jre-headless
Which Java version do you actually need?
Java 8 and Java 11 are older LTS releases. Current software usually requires Java 17 or Java 21, while some server applications (older Minecraft servers, individual plugins or long-lived enterprise software, for example) still depend on Java 8 or Java 11. Only install an older release if your application explicitly asks for it, because newer versions receive security updates for considerably longer.
Enable the universe repository
On Ubuntu the OpenJDK packages live in the "universe" package source. It is already active on most server images. If it is not, enable it like this:
apt install software-properties-common -y
add-apt-repository universe
apt update
Install Java 11
A single command is enough for Java 11:
apt install openjdk-11-jre-headless -y
The jre-headless variant contains only the runtime environment without graphical libraries, which makes it the lean and fitting choice for a server. If you also need a compiler, install openjdk-11-jdk instead.
Install Java 8
Java 8 is just as straightforward, you only have to name a different package:
apt install openjdk-8-jre-headless -y
For development and compiling, use openjdk-8-jdk accordingly.
Alternative: use the Ubuntu default version
If your application does not ask for a specific Java version but simply needs a current Java, the metapackage is the most convenient route. It automatically pulls in the version 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 |
On Ubuntu 22.04 LTS this gives you exactly Java 11, without having to keep the version number in the package name up to date.
Verify the installation
Finally, check whether the installation succeeded. Query the installed Java version:
java -version
If the output shows the major version you wanted (that is 1.8.0 for Java 8 or 11.0 for Java 11), the installation worked.
Set the default Java version
When several JDKs are installed, the alternatives system decides which version starts when you call java. List all available versions like this:
update-alternatives --list java
Then select the default version you want interactively:
update-alternatives --config java
Alternative: Eclipse Temurin via the Adoptium repository
If you need a specific Java build or a version Ubuntu does not ship, the Adoptium repository helps. For Ubuntu 24.04 it provides versions 8 through 26, and the same package source is available for Ubuntu 22.04 as well. Set it up like this:
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
After that, install the version you need:
apt install temurin-8-jre -y
apt install temurin-11-jre -y
The key is deliberately kept as its own file under /etc/apt/keyrings/ and tied to exactly one repository via signed-by=. The apt-key command that used to be common is deprecated and should no longer be used, because a key registered that way is trusted for every package source on the system.
Common errors and how to fix them
"Unable to locate package openjdk-8-jre-headless": The "universe" package source is not active, or the package list is outdated. Run add-apt-repository universe followed by apt update.
The same guide does not work on Debian: That is to be expected. Debian removed Java 8 entirely, and Java 11 as of Debian 12, from its package sources. There the route goes through the Adoptium repository.
java -version shows the wrong version: A different Java installation is set as the default. Correct it with update-alternatives --config java.
An application cannot find Java: In many cases the JAVA_HOME environment variable is missing. Determine the matching path with update-alternatives --list java, then add it permanently to /etc/environment.
Security note: Java 8 and Java 11 receive updates for a considerably shorter period than the current LTS releases. Check regularly whether your application runs on Java 17, Java 21 or Java 25 by now.
Frequently asked questions
How do I install Java 11 on Ubuntu 24.04?
Why can apt not find the package openjdk-8-jre-headless?
How do I check which Java version is active?
How do I set JAVA_HOME on Ubuntu?
Why does the same guide not work on Debian?
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.

