Installing Java 21 on Debian 13 and Debian 12
Java 21 is the current LTS release. Install it on Debian 13 straight from apt, on Debian 12 through the Adoptium repository, or as an Oracle package.
Want to install Java 21 on your Debian 13 (Trixie) or Debian 12 (Bookworm) server? Java 21 is the current LTS release with a long update horizon and the right choice for most new projects. This guide covers three ways to install it.
Requirements
You need SSH access with root privileges (or a user with sudo permissions) on a current Debian system. Debian 13 "Trixie" and Debian 12 "Bookworm" are recommended. Debian 10 reached its end of support in June 2024 and no longer receives regular security updates, so it is not suitable for production use any more.
Start by refreshing the package list on your Debian system and applying the available updates:
apt update && apt upgrade -y
Which Java version ships with which Debian?
Debian swaps out the bundled OpenJDK versions with every major release. For Java 21 that means only Debian 13 carries it in the default repository, older Debian releases do not. This overview shows what actually sits in the official package sources (as of July 2026):
| Package | Debian 13 | Debian 12 | Debian 11 |
|---|---|---|---|
| openjdk-8-jre-headless | not included | not included | not included |
| openjdk-11-jre-headless | not included | not included | 11.0.31 |
| openjdk-17-jre-headless | not included | 17.0.19 | 17.0.19 |
| openjdk-21-jre-headless | 21.0.11 | not included | not included |
| openjdk-25-jre-headless | 25.0.3 | not included | not included |
You can check for yourself at any time whether a package is available on your system:
apt-cache policy openjdk-21-jre-headless
If a version number shows up next to "Candidate", you can install right away. If it says (none) instead, use the Temurin route from the section after next.
Installing Java 21 on Debian 13 from the repository
Debian 13 ships OpenJDK 21 out of the box. That is the simplest and lowest-maintenance route, because security updates then arrive automatically through apt upgrade:
apt install openjdk-21-jre-headless -y
The jre-headless variant contains only the runtime without graphical libraries, which makes it the lean and appropriate choice for a server. If you also need a compiler, install openjdk-21-jdk instead.
You reach the same result through the default-jre-headless metapackage, because on Debian 13 it resolves to exactly Java 21. On Debian 12 the very same metapackage gives you Java 17, and on Debian 11 Java 11.
apt install default-jre-headless -y
If your application does not insist on a specific major version, this is the lowest-maintenance route, because you never have to carry the version number around in the package name.
Installing Java 21 on Debian 12 from the Adoptium repository
Debian 12 does not carry OpenJDK 21 in its main source. The Adoptium repository lets you install Eclipse Temurin 21, a freely available OpenJDK build that is updated through apt just the same.
Set up the package source first:
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
Then install Java 21:
apt install temurin-21-jre -y
The Adoptium repository provides versions 8 through 26 for Debian 13, and the same package source is available for Debian 12 as well. If you need a compiler, take temurin-21-jdk. The signing key lives here in a file of its own under /etc/apt/keyrings/ and is tied to exactly this repository by the signed-by= entry in the sources line. The apt-key command that used to be common has been deprecated since Debian 11 and should no longer be used.
Alternative: installing Oracle JDK 21 as a package
If you specifically need the Oracle JDK, download the package directly and install it with dpkg:
wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb
dpkg -i jdk-21_linux-x64_bin.deb
Keep two things in mind here: the package receives no updates through apt, so you have to watch out for new releases yourself. On top of that, the Oracle JDK comes with its own license terms, which you should review before running it in production. OpenJDK and Eclipse Temurin, by contrast, are covered by an open license.
Verifying the installation
To finish, check whether the installation worked. Query the installed Java version:
java -version
If the output contains the version number 21, Java 21 is set up correctly.
Setting the default Java version
If java -version reports a different release, an older JDK is still set as the default. List all installed Java versions first:
update-alternatives --list java
Then pick the version you want interactively from that list:
update-alternatives --config java
Afterwards check with java -version again to confirm that the right version is now active.
Common errors and fixes
"Unable to locate package openjdk-21-jre-headless": On Debian 12 and Debian 11 this is not a fault in your installation, because the package sources there simply do not contain OpenJDK 21. In that case, use the Adoptium repository from the Debian 12 section.
dpkg reports missing dependencies: Run apt install -f afterwards so the missing packages are pulled in automatically.
java -version still shows an older release after the installation: Set the default version with update-alternatives --config java.
Which version for new projects? Java 21 is an LTS release and will receive security updates for many years. For new applications it is therefore usually the better choice over Java 17 or older releases.
Frequently asked questions
How do I install Java 21 on Debian 13?
How do I get Java 21 onto Debian 12?
Should I use OpenJDK or the Oracle JDK?
java -version still shows an older release after the installation. What now?
Is Java 21 worth it over Java 17?
2024-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.

