How to Install Java on Debian

Install Java on Debian 11, 12, or 13 with apt install openjdk-21-jdk or openjdk-25-jdk, default-jdk metapackages, Eclipse Temurin from Adoptium, and update-java-alternatives. Set JAVA_HOME, verify java -version, compile a sample program, and uninstall cleanly.

Published

Updated

Read time 6 min read

Reviewed byDeepak Prasad

How to Install Java on Debian

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.

NOTE
Install one default JDK for system-wide 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:

bash
. /etc/os-release && echo "$PRETTY_NAME"
apt-cache policy default-jdk default-jre | head -12
apt-cache search '^openjdk-[0-9]+-jdk'

On Trixie:

text
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 apt installs.
  • Enough disk space—each full JDK is roughly 200–400 MB with dependencies.

Check existing Java:

bash
java -version 2>&1 || echo "java: not installed"
javac -version 2>&1 || echo "javac: not installed"
update-java-alternatives --list 2>/dev/null || true

Install the suite default

bash
sudo apt update
sudo apt install -y default-jdk
java -version
javac -version

default-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):

bash
sudo apt install -y openjdk-25-jdk
apt-cache policy openjdk-25-jdk | head -8
text
openjdk-25-jdk:
  Installed: 25.0.3+9-2~deb13u1
  Candidate: 25.0.3+9-2~deb13u1

Install 21 the same way:

bash
sudo apt install -y openjdk-21-jdk
text
ii  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:

bash
sudo apt install -y openjdk-21-jre-headless

Install 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:

bash
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 -version
text
openjdk 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):

text
temurin-17-jdk:
  Candidate: 17.0.19.0.0+10-1

See 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:

  1. Download the .tar.gz or .deb from Oracle for your architecture.
  2. Extract to /opt/jdk-XX or install the .deb with apt on a local package.
  3. Register with update-alternatives or set JAVA_HOME in /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:

bash
update-java-alternatives --list
text
java-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-amd64

Set the active default:

bash
sudo update-java-alternatives --set java-1.25.0-openjdk-amd64
java -version 2>&1 | head -2
text
openjdk version "25.0.3" 2026-04-21
OpenJDK Runtime Environment (build 25.0.3+9-2-deb13u1-Debian)

Switch to Debian OpenJDK 21:

bash
sudo update-java-alternatives --set java-1.21.0-openjdk-amd64
java -version 2>&1 | head -2
text
openjdk 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):

bash
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH="$JAVA_HOME/bin:$PATH"
echo "$JAVA_HOME"
java -version

Examples 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:

bash
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.sh

Note: 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

bash
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 Hello
text
Hello, Java on Debian

If javac: command not found, you installed a JRE only—install openjdk-*-jdk.

Check the manual page:

bash
MANPAGER=cat man java 2>/dev/null | head -6

Update Java

bash
sudo apt update
sudo apt install --only-upgrade 'openjdk-*-jdk' 'temurin-*-jdk'
java -version

List installed JDK packages with list installed packages on Debian:

bash
dpkg -l 'openjdk-*-jdk' 'temurin-*' 2>/dev/null | grep ^ii

Uninstall Java

Remove specific packages—keep the JDK your apps still need:

bash
sudo apt remove --purge openjdk-25-jdk
sudo apt remove --purge temurin-21-jdk
sudo apt autoremove

Remove the Adoptium repository when you no longer use Temurin (see install Temurin on Debian).

After removal, confirm alternatives:

bash
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


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.


Frequently Asked Questions

1. How do I install Java on Debian?

Run sudo apt update && sudo apt install -y default-jdk for the metapackage on your release, or install an explicit version such as openjdk-21-jdk or openjdk-25-jdk on Debian 13. Verify with java -version and javac -version.

2. Which Java version does Debian install by default?

The default-jdk metapackage tracks the primary JDK in each suite: OpenJDK 21 on Debian 13, OpenJDK 17 on Debian 12, and OpenJDK 11 on Debian 11. Run apt-cache policy default-jdk before installing.

3. How do I install Java 21 on Debian 12 without a third-party repo?

Debian 12 ships openjdk-17-jdk in main by default. For Java 21 on Bookworm, add the Eclipse Temurin APT repository and install temurin-21-jdk, or enable backports if your suite publishes openjdk-21-jdk there—check apt-cache policy openjdk-21-jdk first.

4. How do I install Java 8 on Debian?

Debian 11 may still offer openjdk-8-jdk in main. Newer suites drop Java 8 from main—use Eclipse Temurin temurin-8-jdk from Adoptium or a vendor tarball. Oracle JDK 8 requires a manual install from oracle.com.

5. What is the difference between JDK and JRE on Debian?

JDK packages (openjdk-21-jdk) include javac and development tools. JRE packages (openjdk-21-jre) run applications only. Headless variants omit GUI libraries for servers and containers.

6. How do I switch Java versions on Debian?

Run sudo update-java-alternatives --list, then sudo update-java-alternatives --set java-1.21.0-openjdk-amd64 or temurin-21-jdk-amd64. Confirm with java -version.

7. How do I set JAVA_HOME on Debian?

Point JAVA_HOME at the JVM root, for example /usr/lib/jvm/java-21-openjdk-amd64. Use export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java)))) after selecting your default java.

8. Is Oracle Java available in Debian apt?

No official oracle-java package ships in Debian main. Use OpenJDK or Eclipse Temurin from apt, or download Oracle JDK manually from oracle.com/java/technologies/downloads/.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on …