Debian

Install Java (OpenJDK) on Debian 13 – JDK and JRE

OpenJDK is the free, open-source implementation of the Java Platform, Standard Edition. It provides the Java Runtime Environment (JRE) for running Java applications and the Java Development Kit (JDK) for compiling and developing them. Most server-side Java applications – from Apache Tomcat web apps to enterprise middleware – depend on a working JDK or JRE installation.

Original content from computingforgeeks.com - post 69778

This guide covers installing OpenJDK on Debian 13 (Trixie). Debian 13 ships two OpenJDK versions in its official repositories: OpenJDK 21 (the current LTS, and Debian 13’s default) and OpenJDK 25. We will install both JRE and JDK variants, switch between versions using update-alternatives, and configure the JAVA_HOME environment variable.

Prerequisites

  • A server or workstation running Debian 13 (Trixie)
  • Root or sudo access
  • Internet connection to pull packages from Debian repositories

Step 1: Update the Package Index

Start by refreshing the package index to make sure you get the latest available versions.

sudo apt update

Step 2: Install OpenJDK 21 on Debian 13 (Default JDK)

OpenJDK 21 is the default Java version in Debian 13. The default-jdk and default-jre metapackages point to OpenJDK 21. You can install either the full JDK (for development) or just the JRE (for running applications).

Install the JRE (runtime only)

Install the JRE if you only need to run Java applications and do not need to compile code. This is the right choice for production servers running pre-built Java apps like Tomcat or Elasticsearch.

sudo apt install default-jre -y

This pulls in openjdk-21-jre and all required dependencies. You can also install the JRE directly by name.

sudo apt install openjdk-21-jre -y

Install the JDK (development kit)

Install the full JDK if you need to compile Java source code, build projects with Apache Maven or Gradle, or develop Java applications. The JDK includes the JRE plus development tools like javac, jar, and jdb.

sudo apt install default-jdk -y

Or by explicit package name.

sudo apt install openjdk-21-jdk -y

Verify the installation

Check the installed Java version.

$ java -version
openjdk version "21.0.10" 2025-07-15
OpenJDK Runtime Environment (build 21.0.10+7-Debian-1~deb13u1)
OpenJDK 64-Bit Server VM (build 21.0.10+7-Debian-1~deb13u1, mixed mode, sharing)

If you installed the JDK, also verify the compiler.

$ javac -version
javac 21.0.10

Step 3: Install OpenJDK 25 on Debian 13

Debian 13 also ships OpenJDK 25 in its repositories. This is useful when your application or build tool requires the latest Java features. Install the JRE, JDK, or both as needed.

# Install OpenJDK 25 JRE
sudo apt install openjdk-25-jre -y

# Install OpenJDK 25 JDK
sudo apt install openjdk-25-jdk -y

Verify OpenJDK 25 is installed.

$ /usr/lib/jvm/java-25-openjdk-amd64/bin/java -version
openjdk version "25.0.2" 2025-10-14
OpenJDK Runtime Environment (build 25.0.2+10-Debian-1~deb13u2)
OpenJDK 64-Bit Server VM (build 25.0.2+10-Debian-1~deb13u2, mixed mode, sharing)

Step 4: Switch Between Java Versions with update-alternatives

When you have multiple OpenJDK versions installed, use update-alternatives --config java to set the default java command system-wide.

sudo update-alternatives --config java

You will see a numbered list of all installed Java versions. Enter the selection number for the version you want as the default.

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-25-openjdk-amd64/bin/java   2511      auto mode
  1            /usr/lib/jvm/java-21-openjdk-amd64/bin/java   2111      manual mode
  2            /usr/lib/jvm/java-25-openjdk-amd64/bin/java   2511      manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/lib/jvm/java-21-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode

Do the same for the Java compiler if you installed JDK packages.

sudo update-alternatives --config javac

Confirm the active version after switching.

java -version

Step 5: Set JAVA_HOME Environment Variable

Many Java tools – Maven, Gradle, Tomcat, and most application servers – require the JAVA_HOME variable to be set. Create a profile script so it loads automatically for all users.

First, find the path of your active Java installation.

$ readlink -f /usr/bin/java
/usr/lib/jvm/java-21-openjdk-amd64/bin/java

The JAVA_HOME value is the directory one level above bin/, so /usr/lib/jvm/java-21-openjdk-amd64 in this case. Create the profile script.

sudo vi /etc/profile.d/jdk.sh

Add the following content.

export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin

If you switched your default to OpenJDK 25, use /usr/lib/jvm/java-25-openjdk-amd64 instead. Load the new environment.

source /etc/profile.d/jdk.sh

Verify the variable is set correctly.

$ echo $JAVA_HOME
/usr/lib/jvm/java-21-openjdk-amd64

Step 6: Test Java with a Sample Program

Confirm everything works by compiling and running a simple program. Create a file called Hello.java.

vi Hello.java

Add the following content.

public class Hello {
    public static void main(String[] args) {
        System.out.println("OpenJDK is working on Debian 13");
    }
}

Compile and run it.

$ javac Hello.java
$ java Hello
OpenJDK is working on Debian 13

If you see the output above, your JDK installation is fully functional.

JRE vs JDK – Which One to Install

The choice between JRE and JDK depends on your use case.

PackageUse Case
openjdk-21-jre / default-jreRunning pre-built Java applications (Tomcat, Elasticsearch, Kafka, Jenkins)
openjdk-21-jdk / default-jdkCompiling Java source code, building with Maven/Gradle, development work
openjdk-21-jre-headlessServers without a display – no GUI libraries pulled in, smaller footprint
openjdk-21-jdk-headlessBuild servers and CI/CD pipelines – compiler tools without GUI dependencies

For production servers, the headless variants are preferred since they skip unnecessary X11 and GUI libraries, reducing the attack surface and disk usage.

Conclusion

OpenJDK 21 and OpenJDK 25 are now installed on Debian 13, with version switching configured through update-alternatives and JAVA_HOME set for build tools. For production deployments, use the headless JRE packages to minimize the installed footprint, and keep packages updated with regular apt upgrade runs to pick up security patches from the OpenJDK project.

Related Articles

Debian Install and Use .NET Core 6 on Debian 12 / Debian 11 Debian Install and Configure HAProxy on Debian 13/12 Databases Install mycli MySQL AutoCompletion on Ubuntu / Debian CentOS How to Convert ePub file to PDF Format on Linux CLI

Press ESC to close