Java 21 is still the target release for many Spring Boot 3.x services, Gradle builds, and application servers, but Debian does not package it the same way on every stable release. If you need to install OpenJDK 21 on Debian, the clean path depends on whether you are on Debian 13 (Trixie) or one of the older stable releases.
Debian 13 carries openjdk-21-jdk in the default APT sources, while Debian 12 (Bookworm) and Debian 11 (Bullseye) need Eclipse Temurin from Adoptium instead. After Java 21 is in place, you can verify java and javac, switch active JDKs with update-alternatives, set JAVA_HOME, fix the common package-name error, and remove the packages cleanly later.
Install OpenJDK 21 on Debian
Two installation paths matter here. Debian 13 users can stay inside the default repositories, while Debian 12 and Debian 11 need the Temurin 21 packages from Adoptium.
| Method | Channel | Works On | Updates | Best For |
|---|---|---|---|---|
| Debian APT | Debian packages | Debian 13 | Via apt upgrade | Simplest distro-managed OpenJDK 21 install |
| Eclipse Temurin APT | Adoptium Linux packages | Debian 12, Debian 11 | Via apt upgrade | Java 21 on older stable Debian releases |
Most readers should stay with Debian’s own package when they are on Debian 13. Debian 12 and Debian 11 readers should skip straight to Temurin, because openjdk-21-jdk is not packaged in their default APT sources.
Update Debian Before Installing OpenJDK 21
Refresh APT first so Debian 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 file yet, follow the guide on how to add a user to sudoers on Debian before continuing.
Install OpenJDK 21 from Debian Repositories
Debian 13 is the only stable Debian release covered here that publishes openjdk-21-jdk in the default repositories. Use the explicit package names below instead of default-jdk when you want to stay on Java 21.
Confirm that APT can already see the package before you install it:
apt-cache policy openjdk-21-jdk
openjdk-21-jdk:
Installed: (none)
Candidate: 21.0.10+7-1~deb13u1
Version table:
21.0.10+7-1~deb13u1 500
500 http://deb.debian.org/debian trixie/main amd64 Packages
500 http://security.debian.org/debian-security trixie-security/main amd64 Packages
Choose the package variant that matches your workload:
| Package | Includes | Best For |
|---|---|---|
openjdk-21-jdk | Compiler, runtime, and desktop libraries | General development work and IDE use |
openjdk-21-jdk-headless | Compiler and runtime without GUI libraries | Build servers, CI jobs, and containers |
openjdk-21-jre | Desktop runtime only | Running Java applications without compiling them |
openjdk-21-jre-headless | Headless runtime only | Server-side Java application runtime |
Install only the package you need. 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 after the package finishes installing:
java --version
openjdk 21.0.10 2026-01-20 OpenJDK Runtime Environment (build 21.0.10+7-Debian-1deb13u1) OpenJDK 64-Bit Server VM (build 21.0.10+7-Debian-1deb13u1, mixed mode, sharing)
If you installed a JDK package rather than a JRE-only package, confirm the compiler is available too:
javac --version
javac 21.0.10
Check the active Java binary path when you need the exact installation directory:
readlink -f /usr/bin/java
/usr/lib/jvm/java-21-openjdk-amd64/bin/java
To update Debian’s OpenJDK 21 package later without upgrading unrelated packages, run the targeted upgrade below and swap in the package name you actually installed if you picked a JRE or headless variant:
sudo apt update
sudo apt install --only-upgrade openjdk-21-jdk -y
Install Eclipse Temurin 21 on Debian
Debian 12 and Debian 11 do not ship openjdk-21-jdk, so use Adoptium’s Temurin 21 packages when you need Java 21 on those releases. This path keeps updates inside APT instead of forcing a manual tarball install.
Install the packages needed to add the repository securely:
sudo apt install ca-certificates curl gpg -y
Import the Adoptium signing key into Debian’s keyring directory next:
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 that APT expects under /usr/share/keyrings/. The -fsSL flags tell curl to fail on HTTP errors, stay quiet, and follow redirects. If you use that command often outside package setup too, learn the curl command in Linux for the wider flag set.
Create the DEB822 source file after the key is in place. The command writes the file as root with sudo tee, because plain > redirection does not inherit sudo privileges.
. /etc/os-release
printf '%s\n' \
"Types: deb" \
"URIs: https://packages.adoptium.net/artifactory/deb" \
"Suites: $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 first line loads your Debian release details into the current shell. Debian 12 writes bookworm into the Suites: line, while Debian 11 writes bullseye.
Refresh APT after adding the new source:
sudo apt update
Relevant output includes:
Get:4 https://packages.adoptium.net/artifactory/deb bookworm InRelease [7,507 B] Reading package lists...
Confirm that APT can see the Temurin 21 package before you install it:
apt-cache policy temurin-21-jdk
temurin-21-jdk:
Installed: (none)
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 bookworm/main amd64 Packages
21.0.10.0.0+7-0 500
500 https://packages.adoptium.net/artifactory/deb bookworm/main amd64 Packages
Debian 11 shows the same package version from the
bullseyesuite instead ofbookworm. The package name staystemurin-21-jdkon both releases.
Install the full JDK when you need Java 21 for builds, compilers, or tools like Apache Maven on Debian:
sudo apt install temurin-21-jdk -y
If you only need the runtime, swap in temurin-21-jre instead. Server-only hosts can still keep the footprint smaller by avoiding unnecessary desktop libraries while building containers or services on Docker on Debian.
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)
Confirm the compiler too when you installed the JDK package:
javac --version
javac 21.0.10
The active Java path confirms whether you are using Temurin or Debian’s own package:
readlink -f /usr/bin/java
/usr/lib/jvm/temurin-21-jdk-amd64/bin/java
Temurin 21 updates through the same Adoptium repository, so a normal targeted APT upgrade keeps it current later:
sudo apt update
sudo apt install --only-upgrade temurin-21-jdk -y
Compare Debian Default Java Versions for OpenJDK 21
Debian’s default-jdk package changes by release, which is why OpenJDK 21 is a native package on one release and an alternate vendor install on the older ones.
| Debian Release | default-jdk Maps To | OpenJDK 21 Status | What It Means |
|---|---|---|---|
| Debian 13 (Trixie) | OpenJDK 21.x | openjdk-21-jdk is available in the default repositories | Use Debian APT unless you have a vendor-specific reason not to |
| Debian 12 (Bookworm) | OpenJDK 17.x | openjdk-21-jdk is not packaged in the default APT sources | Use Temurin 21 when a project needs Java 21 |
| Debian 11 (Bullseye) | OpenJDK 11.x | openjdk-21-jdk is not packaged in the default APT sources | Use Temurin 21 when you need a supported Java 21 build |
If you would rather stay on the distro-default branch for Debian 12, compare OpenJDK 17 on Debian. If a newer project is already moving to the next LTS line on Debian 13, compare OpenJDK 25 on Debian before you pin Java 21 out of habit.
Manage Multiple Java Versions on Debian
Debian uses update-alternatives to manage the active java and javac symlinks. That lets you keep more than one JDK installed without editing /usr/bin by hand.
Check the Active Java Runtime on Debian
List the installed runtime choices first so you can see which JDK currently owns /usr/bin/java:
sudo update-alternatives --display java
java - auto mode link best version is /usr/lib/jvm/java-25-openjdk-amd64/bin/java link currently points to /usr/lib/jvm/java-25-openjdk-amd64/bin/java link java is /usr/bin/java slave java.1.gz is /usr/share/man/man1/java.1.gz /usr/lib/jvm/java-21-openjdk-amd64/bin/java - priority 2111 slave java.1.gz: /usr/lib/jvm/java-21-openjdk-amd64/man/man1/java.1.gz /usr/lib/jvm/java-25-openjdk-amd64/bin/java - priority 2511
If you want to switch the active runtime interactively, run sudo update-alternatives --config java and choose the Java 21 entry.
Check the Active Java Compiler on Debian
Keep the compiler aligned with the runtime so your build tools and bytecode targets stay on the same Java major version:
sudo update-alternatives --display javac
javac - auto mode link best version is /usr/lib/jvm/java-25-openjdk-amd64/bin/javac link currently points to /usr/lib/jvm/java-25-openjdk-amd64/bin/javac link javac is /usr/bin/javac slave javac.1.gz is /usr/share/man/man1/javac.1.gz /usr/lib/jvm/java-21-openjdk-amd64/bin/javac - priority 2111 slave javac.1.gz: /usr/lib/jvm/java-21-openjdk-amd64/man/man1/javac.1.gz /usr/lib/jvm/java-25-openjdk-amd64/bin/javac - priority 2511
Use sudo update-alternatives --config javac when you need to move the compiler back to Java 21 after installing another JDK.
Find the Active JAVA_HOME Path on Debian
Check the active Java binary first, then use the parent directory as JAVA_HOME. With Debian’s own OpenJDK 21 package selected, the active path looks like this:
readlink -f /usr/bin/java
/usr/lib/jvm/java-21-openjdk-amd64/bin/java
With Debian’s own OpenJDK 21 package selected, JAVA_HOME is /usr/lib/jvm/java-21-openjdk-amd64. With Temurin 21 selected, it is /usr/lib/jvm/temurin-21-jdk-amd64.
The safest way to capture the actual JAVA_HOME directory is to strip the trailing /bin/java from the active binary path. With Temurin 21 active, the command returns:
dirname "$(dirname "$(readlink -f /usr/bin/java)")"
/usr/lib/jvm/temurin-21-jdk-amd64
If a build tool needs the variable exported later, add the path that command prints to your shell profile as export JAVA_HOME=/path/to/jdk.
Troubleshoot OpenJDK 21 on Debian
Most OpenJDK 21 problems on Debian come from package-name assumptions or from another JDK staying active after the install. These checks narrow the issue quickly.
Fix Unable to Locate Package OpenJDK 21 on Debian
Debian 12 and Debian 11 do not ship openjdk-21-jdk, so APT returns this error even after a normal apt update:
Reading package lists... Building dependency tree... Reading state information... E: Unable to locate package openjdk-21-jdk
On Debian 12 or Debian 11, install temurin-21-jdk instead after adding the Adoptium repository. On Debian 13, rerun sudo apt update and check that the default Debian repositories are enabled before retrying openjdk-21-jdk.
Fix the Wrong Active Java Version on Debian
If java --version still reports Java 17 or Java 25 after you install Java 21, switch both the runtime and compiler back to the Java 21 entries:
sudo update-alternatives --config java
sudo update-alternatives --config javac
java --version
javac --version
openjdk 21.0.10 2026-01-20 OpenJDK Runtime Environment (build 21.0.10+7-Debian-1deb13u1) OpenJDK 64-Bit Server VM (build 21.0.10+7-Debian-1deb13u1, mixed mode, sharing) javac 21.0.10
Remove OpenJDK 21 or Temurin 21 on Debian
Remove only the package set you actually installed. Debian’s own OpenJDK packages and Adoptium’s Temurin packages use different package names and cleanup steps.
Remove Debian OpenJDK 21 Packages on Debian
Use this package cleanup path when you installed Java 21 from Debian 13’s own repositories. If you only installed one package variant, remove that package name instead of the full list.
sudo apt remove --autoremove openjdk-21-jdk openjdk-21-jdk-headless openjdk-21-jre openjdk-21-jre-headless
Verify that Debian no longer has the package installed:
apt-cache policy openjdk-21-jdk
openjdk-21-jdk:
Installed: (none)
Candidate: 21.0.10+7-1~deb13u1
Version table:
21.0.10+7-1~deb13u1 500
500 http://deb.debian.org/debian trixie/main amd64 Packages
Remove Temurin 21 and the Adoptium Repository on Debian
Use the Temurin cleanup path on Debian 12 or Debian 11 after an Adoptium install. Remove the package first, then delete the repository source and key.
sudo apt remove --autoremove temurin-21-jdk temurin-21-jre
Delete the Adoptium source files after the package is gone, then refresh APT so Debian drops the cached repo metadata:
sudo rm -f /etc/apt/sources.list.d/adoptium.sources /usr/share/keyrings/adoptium.gpg
sudo apt update
Verify that the Temurin package is gone after the removal:
dpkg-query -W temurin-21-jdk 2>/dev/null || echo temurin-21-jdk not installed
temurin-21-jdk not installed
Confirm that the repository files are gone too:
test ! -f /etc/apt/sources.list.d/adoptium.sources && test ! -f /usr/share/keyrings/adoptium.gpg && echo Adoptium repo files removed
Adoptium repo files removed
At that point, apt-cache policy temurin-21-jdk returns no output because Debian no longer sees the package from an active Adoptium source.
OpenJDK 21 on Debian FAQ
Debian 13 packages openjdk-21-jdk in the default repositories. Debian 12 and Debian 11 do not, so those releases need the temurin-21-jdk package from Adoptium instead.
That package name is only available from Debian 13’s default repositories. On Debian 12 and Debian 11, add the Adoptium repository and install temurin-21-jdk instead.
Only on Debian 13. Debian 12 maps default-jdk to OpenJDK 17, and Debian 11 maps it to OpenJDK 11, so use the explicit Java 21 package names when you need this major version.
With Debian’s own package, JAVA_HOME is usually /usr/lib/jvm/java-21-openjdk-amd64. With Temurin 21, it is usually /usr/lib/jvm/temurin-21-jdk-amd64. The safest check is readlink -f /usr/bin/java, then use that path’s parent directory as JAVA_HOME.
Conclusion
OpenJDK 21 is running on Debian once you match the package source to your release. Debian APT keeps Trixie simple, while Temurin covers Bookworm and Bullseye when a Spring Boot, Gradle, or application-server stack still needs Java 21. From there, the next decision is whether your projects stay on the Java 21 LTS line or move forward to a newer branch later.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>