Many Java stacks still target 21 even after Ubuntu 26.04 moved its default JDK to OpenJDK 25. If you need to install OpenJDK 21 on Ubuntu for Spring Boot 3.x, build servers, or pinned enterprise apps, Ubuntu’s own archives still carry the package. Eclipse Temurin remains an alternate vendor build on 24.04 and 22.04.
Ubuntu 24.04 makes OpenJDK 21 the default Java line, Ubuntu 22.04 keeps it in Universe, and Ubuntu 26.04 currently ships OpenJDK 21 as a compatibility package alongside OpenJDK 25. Both installation paths stay inside APT and update-alternatives, so you avoid manual tarball downloads and hand-set symlinks unless you intentionally want a different archive-based workflow.
Update Ubuntu Before You Install OpenJDK 21
Refresh APT first so Ubuntu pulls the current package metadata and security updates. The -y flag accepts the upgrade prompt automatically.
sudo apt update
sudo apt upgrade -y
These commands use
sudofor package-management tasks that need root privileges. If your account is not in the sudoers group yet, follow the steps to add a new user to sudoers on Ubuntu before continuing.
Install OpenJDK 21 on Ubuntu
Two package sources matter here. Ubuntu’s own archive is the simplest path, while Eclipse Temurin gives Ubuntu 24.04 and 22.04 users an Adoptium build that still updates through APT.
| Method | Channel | Works On | Updates | Best For |
|---|---|---|---|---|
| Ubuntu archive | Ubuntu packages | 26.04, 24.04, 22.04 | Via apt upgrade | Fastest setup, distro-managed Java packages |
| Eclipse Temurin APT | Adoptium Linux packages | 24.04, 22.04 | Via apt upgrade | Adoptium vendor build with TCK and AQAvit checks |
Most readers should start with the Ubuntu archive method. Choose Eclipse Temurin only when you specifically want Adoptium’s vendor build on Ubuntu 24.04 or 22.04.
Ubuntu 26.04 can install
openjdk-21-jdkfrom Universe, but the current package reports a21.0.11-earuntime whiledefault-jdkalready points to OpenJDK 25. If you need a non-EA Java 21 build on Ubuntu 26.04, Ubuntu 24.04 or 22.04 is the cleaner route right now, and Adoptium does not publish aresoluteRelease file yet.
Install OpenJDK 21 from Ubuntu Repositories
Install OpenJDK 21 on Ubuntu with sudo apt install openjdk-21-jdk -y when you want the distro-managed package and normal APT updates. Ubuntu 24.04 publishes openjdk-21-jdk from Main, while Ubuntu 22.04 and 26.04 publish it from Universe.
| Package | Includes | Best For |
|---|---|---|
| openjdk-21-jdk | Full compiler, runtime, and desktop dependencies | Desktop development and general Java work |
| openjdk-21-jdk-headless | Compiler and runtime without GUI libraries | Servers, CI runners, and containers |
| openjdk-21-jre | Desktop runtime only | Running Java apps without compiling them |
| openjdk-21-jre-headless | Headless runtime only | Server-side Java application runtime |
Choose one package variant rather than installing all four. Most readers either want the full JDK or the headless JDK.
# Full development kit
sudo apt install openjdk-21-jdk -y
# Headless development kit for servers and CI
sudo apt install openjdk-21-jdk-headless -y
# Runtime only
sudo apt install openjdk-21-jre -y
# Headless runtime only
sudo apt install openjdk-21-jre-headless -y
Verify the active runtime with java --version. Ubuntu 26.04 currently reports an EA build string here, while Ubuntu 24.04 and 22.04 report stable 21.0.10 builds.
java --version
openjdk 21.0.11-ea 2026-04-21 OpenJDK Runtime Environment (build 21.0.11-ea+5-[Ubuntu-1]) OpenJDK 64-Bit Server VM (build 21.0.11-ea+5-[Ubuntu-1], mixed mode, sharing)
If you installed a JDK package rather than a JRE-only package, confirm the compiler is present too:
javac --version
javac 21.0.11-ea
On amd64, the active Java binary resolves to /usr/lib/jvm/java-21-openjdk-amd64/bin/java. Ubuntu 24.04 packages OpenJDK 21 as 21.0.10+7-1~24.04 from noble-updates/main, Ubuntu 22.04 packages it as 21.0.10+7-1~22.04 from jammy-updates/universe, and Ubuntu 26.04 currently publishes 21.0.11~5ea-1 from resolute/universe.
Install Eclipse Temurin 21 on Ubuntu
Install Eclipse Temurin 21 on Ubuntu when you want Adoptium’s TCK-tested and AQAvit-verified build rather than Ubuntu’s archive packages.
This Adoptium repo method currently works on Ubuntu 24.04 (noble) and 22.04 (jammy). Ubuntu 26.04 (resolute) is not ready for this repo yet because
https://packages.adoptium.net/artifactory/debreturns404 Not Foundfor theresoluteRelease file.
Download the Adoptium signing key and store it in a dedicated keyring file so APT can verify the repository metadata.
curl -fsSL https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo gpg --dearmor --yes -o /usr/share/keyrings/adoptium.gpg
The downloaded key is ASCII-armored, and gpg --dearmor converts it into the binary keyring file APT expects under /usr/share/keyrings/.
Create the Adoptium source file in DEB822 format next. The command writes the file as root with sudo tee, because plain > redirection does not inherit sudo privileges.
printf '%s\n' \
'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' | sudo tee /etc/apt/sources.list.d/adoptium.sources > /dev/null
The Suites: line inserts noble on Ubuntu 24.04 and jammy on Ubuntu 22.04. The architecture substitution keeps the same file correct on amd64 and arm64 systems without hardcoding one package arch.
Refresh APT after adding the repo so Ubuntu can read the new package metadata:
sudo apt update
Get:5 https://packages.adoptium.net/artifactory/deb noble InRelease [7,501 B] Get:6 https://packages.adoptium.net/artifactory/deb noble/main amd64 Packages [10.9 kB]
Install the Temurin 21 JDK package once the repo metadata is available:
sudo apt install temurin-21-jdk -y
If you only need the runtime, Adoptium also publishes temurin-21-jre.
Verify the Temurin runtime after installation:
java --version
openjdk 21.0.10 2026-01-20 LTS OpenJDK Runtime Environment Temurin-21.0.10+7 (build 21.0.10+7-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.10+7 (build 21.0.10+7-LTS, mixed mode, sharing)
APT should also show the package coming from Adoptium’s repo:
apt-cache policy temurin-21-jdk
temurin-21-jdk:
Installed: 21.0.10.0.0+7-1
Candidate: 21.0.10.0.0+7-1
Version table:
*** 21.0.10.0.0+7-1 500
500 https://packages.adoptium.net/artifactory/deb noble/main amd64 Packages
100 /var/lib/dpkg/status
Update Temurin 21 on Ubuntu
Temurin 21 updates through the same Adoptium repo, so a normal APT refresh and targeted package upgrade keeps it current.
sudo apt update
sudo apt install --only-upgrade temurin-21-jdk -y
If you installed the runtime-only package instead, swap in temurin-21-jre for the upgrade command.
Compare Ubuntu Default Java Versions for OpenJDK 21
Ubuntu’s default Java line changes by release, which is why OpenJDK 21 feels like the default choice on one LTS and a compatibility install on another.
| Ubuntu Release | default-jdk Maps To | OpenJDK 21 Package Status | What It Means |
|---|---|---|---|
| Ubuntu 26.04 | OpenJDK 25.x | openjdk-21-jdk is available in Universe as 21.0.11~5ea-1 | Use OpenJDK 21 mainly for compatibility testing or pinned application requirements |
| Ubuntu 24.04 | OpenJDK 21.x | openjdk-21-jdk is available in Main as 21.0.10+7-1~24.04 | Simplest stable Java 21 install on current Ubuntu LTS |
| Ubuntu 22.04 | OpenJDK 11.x | openjdk-21-jdk is available in jammy-updates/universe as 21.0.10+7-1~22.04 | Useful when an older LTS host still needs Java 21 for application compatibility |
If your workload still follows Ubuntu 22.04’s older default Java line, compare OpenJDK 11 on Ubuntu. If a framework vendor has only certified Java 17 so far, compare OpenJDK 17 on Ubuntu. If Ubuntu 26.04’s default Java 25 line already matches your framework support, compare OpenJDK 25 on Ubuntu before pinning Java 21 just out of habit.
Manage Multiple Java Versions on Ubuntu
Ubuntu uses update-alternatives to switch between installed Java runtimes and compilers. That keeps /usr/bin/java and /usr/bin/javac pointed at the version you actually want to use.
Switch the Default Java Runtime on Ubuntu
Run the interactive selector when multiple Java runtimes are installed and you want to switch the system default.
sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 2111 auto mode 1 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode 2 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 2111 manual mode
Choose the number you want, then rerun java --version to confirm the change.
Switch the Default Java Compiler on Ubuntu
Keep the compiler aligned with the runtime so your builds and bytecode targets stay on the same Java version.
sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-21-openjdk-amd64/bin/javac 2111 auto mode 1 /usr/lib/jvm/java-17-openjdk-amd64/bin/javac 1711 manual mode 2 /usr/lib/jvm/java-21-openjdk-amd64/bin/javac 2111 manual mode
Use the same major version for java and javac unless you have a very specific cross-compilation reason not to.
Find the Active JAVA_HOME Path on Ubuntu
Check the active Java path first, then use the parent directory as JAVA_HOME.
readlink -f /usr/bin/java
/usr/lib/jvm/java-21-openjdk-amd64/bin/java
Remove the trailing /bin/java to get JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64. If Temurin is the active runtime instead, the same command returns /usr/lib/jvm/temurin-21-jdk-amd64/bin/java. For a full per-user or system-wide walkthrough, follow the guide on setting the Java environment path in Ubuntu.
Troubleshoot OpenJDK 21 on Ubuntu
The most common OpenJDK 21 issues on Ubuntu are missing Universe packages, the wrong Java version staying active, or Temurin repo support not matching the Ubuntu release you are on.
Fix OpenJDK 21 Package Not Found on Ubuntu 22.04 or 26.04
If apt install openjdk-21-jdk fails with Unable to locate package, the Universe repository is usually disabled on a minimal or customized system. Check for active Universe entries first:
grep -R "universe" /etc/apt/sources.list /etc/apt/sources.list.d/
/etc/apt/sources.list:deb http://au.archive.ubuntu.com/ubuntu/ jammy universe /etc/apt/sources.list:deb http://au.archive.ubuntu.com/ubuntu/ jammy-updates universe /etc/apt/sources.list:deb http://au.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
Ubuntu 26.04 shows the same pattern with resolute instead of jammy. If these lines are missing, enable Universe and refresh APT:
sudo add-apt-repository universe -y
sudo apt update
Once Universe is enabled, retry the package install. Only Universe is required for OpenJDK 21, but if you want the broader background on Ubuntu repository components, use the guide to enable Universe and Multiverse in Ubuntu.
Fix Eclipse Temurin 21 Package Not Found on Ubuntu 26.04
Temurin 21 is not a working APT option on Ubuntu 26.04 yet because Adoptium does not publish a resolute Release file. Use the Ubuntu archive method on 26.04, or move the Temurin 21 workflow to Ubuntu 24.04 or 22.04 until Adoptium adds resolute support.
Fix the Wrong Java Version on Ubuntu
If Java 17, 25, or another version still answers after you install 21, check both the runtime and the compiler before changing alternatives.
java --version
javac --version
openjdk 21.0.10 2026-01-20 OpenJDK Runtime Environment (build 21.0.10+7-Ubuntu-124.04) OpenJDK 64-Bit Server VM (build 21.0.10+7-Ubuntu-124.04, mixed mode, sharing) javac 21.0.10
If those commands disagree, rerun update-alternatives --config java and update-alternatives --config javac, then choose the same JDK path for both.
Remove OpenJDK 21 from Ubuntu
Choose the removal steps that match the package source you used. Ubuntu archive packages and Temurin packages should be cleaned up separately.
Remove Ubuntu Archive OpenJDK 21
Remove the Ubuntu-packaged OpenJDK 21 variants and then clear any orphaned dependencies.
sudo apt remove --purge openjdk-21-jdk openjdk-21-jdk-headless openjdk-21-jre openjdk-21-jre-headless -y
sudo apt autoremove -y
If you only installed one JRE package, remove just that package name instead of all four variants.
Remove Eclipse Temurin 21
Remove the Temurin package first, then remove any unused dependencies it pulled in.
sudo apt remove --purge temurin-21-jdk temurin-21-jre -y
sudo apt autoremove -y
If you no longer need any Adoptium packages, remove the repo file and keyring too, then refresh APT.
sudo rm -f /etc/apt/sources.list.d/adoptium.sources
sudo rm -f /usr/share/keyrings/adoptium.gpg
sudo apt update
Verify OpenJDK 21 Removal
Check the Ubuntu package state first. After removing the archive packages, apt-cache policy should show Installed: (none) while the repository candidate remains available.
apt-cache policy openjdk-21-jdk
openjdk-21-jdk:
Installed: (none)
Candidate: 21.0.10+7-1~24.04
Version table:
21.0.10+7-1~24.04 500
500 http://au.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages
If you also removed the Adoptium source, confirm APT no longer sees the Temurin package:
apt show temurin-21-jdk
WARNING: apt does not have a stable CLI interface. Use with caution in scripts. E: No packages found
If you exported
JAVA_HOMEmanually in~/.bashrc,~/.profile, or a service unit, remove or update that path after uninstalling OpenJDK 21. Build tools fail quickly whenJAVA_HOMEstill points to a deleted JDK directory.
OpenJDK 21 on Ubuntu FAQ
Yes. Ubuntu 22.04 publishes openjdk-21-jdk through jammy-updates/universe. If APT cannot find the package, the Universe component is usually disabled on that system.
No. default-jdk maps to OpenJDK 11 on Ubuntu 22.04, OpenJDK 21 on Ubuntu 24.04, and OpenJDK 25 on Ubuntu 26.04. Install openjdk-21-jdk explicitly when you want Java 21 across all supported Ubuntu LTS releases.
Use openjdk-21-jdk for normal development work, openjdk-21-jdk-headless for servers and CI jobs that do not need GUI libraries, openjdk-21-jre to run desktop Java applications, and openjdk-21-jre-headless to run server-side Java applications without the compiler.
Not through the Debian or Ubuntu APT repo yet. The Adoptium repo currently returns 404 Not Found for the resolute Release file, so Ubuntu 26.04 users should use the Ubuntu archive method for Java 21 or move the Temurin 21 workflow to Ubuntu 24.04 or 22.04.
Conclusion
OpenJDK 21 is installed on Ubuntu and ready for application runtimes, compilers, and version switching through update-alternatives. If your build also needs dependency management, install Apache Maven on Ubuntu. If Ubuntu 26.04’s default Java line already suits your stack, compare OpenJDK 25 on Ubuntu next.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>