Java on Debian usually means OpenJDK packages in main—free, maintained with the distribution, and integrated with update-java-alternatives. Current LTS lines (21) and newer releases (25 on Trixie) install with apt. Older majors (8, 11, 17) depend on your Debian release; when Debian drops a version, Eclipse Temurin from Adoptium fills the gap.
This guide covers install Java on Debian for Debian 11 (Bullseye), 12 (Bookworm), and 13 (Trixie): default-jdk, versioned openjdk-*-jdk packages, Temurin (summary—full steps in install Temurin on Debian), Oracle manual installs, JAVA_HOME, version switching, and uninstall. I ran the commands on Debian 13 and kept real terminal output below.
Tested on: Debian 13 (trixie); kernel 6.12.94+deb13-amd64; amd64; OpenJDK 21.0.11, OpenJDK 25.0.3, and Temurin 21.0.11+10.
java unless you deliberately manage alternatives. Application-specific runtimes (for example the JBR bundled with Android Studio) do not require changing the system JDK.
Choose an install method
| Method | Best for | On Debian 13 (tested) |
|---|---|---|
apt install default-jdk |
Quick install of the suite default | Pulls OpenJDK 21 (2:1.21-76) |
openjdk-21-jdk / openjdk-25-jdk |
Pin a specific OpenJDK major | 21.0.11 and 25.0.3 in main |
| Eclipse Temurin | Java 8/17/21/25 when Debian main lacks your major | temurin-21-jdk from Adoptium |
| Oracle JDK tarball | Vendor support contract or Oracle-specific tooling | Manual download only—not in Debian apt |
Most readers should use openjdk-<version>-jdk from Debian when that version exists in their suite. Add Temurin when apt-cache policy openjdk-17-jdk (or your target) shows no Candidate.
What each Debian release ships
Per Debian Wiki — Java and package names in main:
| Debian release | Typical default-jdk |
Common openjdk-*-jdk packages |
|---|---|---|
| 13 (Trixie) | OpenJDK 21 | 21, 25 (tested—no 8, 11, or 17 in main here) |
| 12 (Bookworm) | OpenJDK 17 | 17; use Temurin or backports for 21 |
| 11 (Bullseye) | OpenJDK 11 | 11; 8 may still be available—run apt-cache search openjdk |
Always confirm on your host:
. /etc/os-release && echo "$PRETTY_NAME"
apt-cache policy default-jdk default-jre | head -12
apt-cache search '^openjdk-[0-9]+-jdk'On Trixie:
Debian GNU/Linux 13 (trixie)
default-jdk:
Candidate: 2:1.21-76
openjdk-21-jdk - OpenJDK Development Kit (JDK)
openjdk-21-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-25-jdk - OpenJDK Development Kit (JDK)
openjdk-25-jdk-headless - OpenJDK Development Kit (JDK) (headless)Prerequisites
- Debian 11, 12, or 13 on amd64 (arm64 OpenJDK packages exist for many releases).
- sudo for
aptinstalls. - Enough disk space—each full JDK is roughly 200–400 MB with dependencies.
Check existing Java:
java -version 2>&1 || echo "java: not installed"
javac -version 2>&1 || echo "javac: not installed"
update-java-alternatives --list 2>/dev/null || trueInstall OpenJDK with apt (recommended)
Install the suite default
sudo apt update
sudo apt install -y default-jdk
java -version
javac -versiondefault-jdk is a metapackage—on Trixie it depends on OpenJDK 21, not Java 25.
Install a specific OpenJDK major
When you need an explicit version (for example 25 on Trixie):
sudo apt install -y openjdk-25-jdk
apt-cache policy openjdk-25-jdk | head -8openjdk-25-jdk:
Installed: 25.0.3+9-2~deb13u1
Candidate: 25.0.3+9-2~deb13u1Install 21 the same way:
sudo apt install -y openjdk-21-jdkii openjdk-21-jdk 21.0.11+10-1~deb13u2 amd64 OpenJDK Development Kit (JDK)JDK, JRE, and headless variants
| Package pattern | Use case |
|---|---|
openjdk-*-jdk |
Development—includes javac |
openjdk-*-jre |
Run Java apps only |
*-headless |
Servers, CI, containers—no AWT/Swing GUI libs |
Example for a minimal server:
sudo apt install -y openjdk-21-jre-headlessInstall Eclipse Temurin (Adoptium)
When Debian main does not ship your Java major—common for Java 21 on Bookworm or Java 8 on newer suites—use Eclipse Temurin:
sudo apt install -y wget gpg
sudo install -d -m 0755 /etc/apt/keyrings
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public \
| gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null
echo "deb [signed-by=/etc/apt/trusted.gpg.d/adoptium.gpg] https://packages.adoptium.net/artifactory/deb \
$(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" \
| sudo tee /etc/apt/sources.list.d/adoptium.list
sudo apt update
sudo apt install -y temurin-21-jdk
java -versionopenjdk version "21.0.11" 2026-04-21 LTS
OpenJDK Runtime Environment Temurin-21.0.11+10 (build 21.0.11+10-LTS)Temurin 17 on Trixie (when Debian main has no openjdk-17-jdk):
temurin-17-jdk:
Candidate: 17.0.19.0.0+10-1See install Temurin on Debian for tarball installs, update-alternatives, and uninstall.
Install Oracle JDK manually
Oracle JDK is not in Debian apt (apt-cache search oracle-java returns nothing useful on Trixie). Download from Oracle Java downloads or use the legacy java.com Linux x64 installer for the JRE.
Typical workflow:
- Download the
.tar.gzor.debfrom Oracle for your architecture. - Extract to
/opt/jdk-XXor install the.debwith apt on a local package. - Register with
update-alternativesor setJAVA_HOMEin/etc/profile.d/.
Most open-source workloads on Debian should prefer OpenJDK or Temurin (OpenJDK install guide).
Switch between installed JDKs
After multiple JDK packages are installed:
update-java-alternatives --listjava-1.21.0-openjdk-amd64 2111 /usr/lib/jvm/java-1.21.0-openjdk-amd64
java-1.25.0-openjdk-amd64 2511 /usr/lib/jvm/java-1.25.0-openjdk-amd64
temurin-21-jdk-amd64 2111 /usr/lib/jvm/temurin-21-jdk-amd64Set the active default:
sudo update-java-alternatives --set java-1.25.0-openjdk-amd64
java -version 2>&1 | head -2openjdk version "25.0.3" 2026-04-21
OpenJDK Runtime Environment (build 25.0.3+9-2-deb13u1-Debian)Switch to Debian OpenJDK 21:
sudo update-java-alternatives --set java-1.21.0-openjdk-amd64
java -version 2>&1 | head -2openjdk version "21.0.11" 2026-04-21
OpenJDK Runtime Environment (build 21.0.11+10-1-deb13u2-Debian)Installing OpenJDK 25 does not automatically change the default when Temurin 21 shares the same priority—explicitly --set the JDK you want.
Set JAVA_HOME
Point JAVA_HOME at the JVM root (parent of bin):
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH="$JAVA_HOME/bin:$PATH"
echo "$JAVA_HOME"
java -versionExamples after selecting each alternative:
| Default JDK | Typical JAVA_HOME |
|---|---|
| Debian OpenJDK 21 | /usr/lib/jvm/java-21-openjdk-amd64 |
| Debian OpenJDK 25 | /usr/lib/jvm/java-25-openjdk-amd64 |
| Temurin 21 | /usr/lib/jvm/temurin-21-jdk-amd64 |
Persist system-wide:
echo 'export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64' | sudo tee /etc/profile.d/java.sh
echo 'export PATH="$JAVA_HOME/bin:$PATH"' | sudo tee -a /etc/profile.d/java.shNote: update-java-alternatives names like java-1.21.0-openjdk-amd64 differ from directory names like java-21-openjdk-amd64—use readlink or the path from --list.
Verify with a sample program
mkdir -p ~/javatest
cat > ~/javatest/Hello.java <<'EOF'
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java on Debian");
}
}
EOF
javac ~/javatest/Hello.java
java -cp ~/javatest HelloHello, Java on DebianIf javac: command not found, you installed a JRE only—install openjdk-*-jdk.
Check the manual page:
MANPAGER=cat man java 2>/dev/null | head -6Update Java
sudo apt update
sudo apt install --only-upgrade 'openjdk-*-jdk' 'temurin-*-jdk'
java -versionList installed JDK packages with list installed packages on Debian:
dpkg -l 'openjdk-*-jdk' 'temurin-*' 2>/dev/null | grep ^iiUninstall Java
Remove specific packages—keep the JDK your apps still need:
sudo apt remove --purge openjdk-25-jdk
sudo apt remove --purge temurin-21-jdk
sudo apt autoremoveRemove the Adoptium repository when you no longer use Temurin (see install Temurin on Debian).
After removal, confirm alternatives:
update-java-alternatives --list
java -version 2>&1 || echo "no default java"Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Package 'openjdk-21-jdk' has no installation candidate |
Wrong suite—Bookworm defaults to 17 | Install openjdk-17-jdk or add Temurin |
| Need Java 8 on Bullseye+ | Removed from newer suites | temurin-8-jdk from Adoptium or vendor tarball |
java -version unchanged after new install |
Old alternative still selected | sudo update-java-alternatives --set … |
javac: command not found |
JRE-only package | sudo apt install openjdk-*-jdk |
| Two JDK 21 builds, confusing output | Both Debian and Temurin installed | Compare vendor string in java -version; pick one default |
| Oracle installer not found in apt | Expected—proprietary | Download from Oracle |
References
- Debian Wiki — Java
- OpenJDK — install
- DigitalOcean — install Java with apt on Debian
- Oracle Java downloads
- On-site: install Temurin on Debian, install a .deb file, install sudo, apt command, list installed packages
Summary
Install Java on Debian with sudo apt install default-jdk or an explicit openjdk-21-jdk / openjdk-25-jdk when your suite ships it. On Trixie, main provides 21 and 25; use Eclipse Temurin for older majors or when Debian lacks your version. Switch defaults with update-java-alternatives, set JAVA_HOME to the JVM directory, verify with java -version and a javac compile, and remove unused JDK packages with apt remove --purge.

