How to Install Java on Debian 12 (Bookworm)

Learn how to easily install Java on Debian 12 (Bookworm) with our step-by-step guide. Enhance your system for powerful Java applications!

Java, a versatile and powerful programming language, is an essential tool for developers and users. It enables the creation of robust applications, runs on multiple platforms, and plays a crucial role in the functioning of many modern software systems.

This guide will walk you through the step-by-step process of installing Java on Debian 12 (Bookworm).

Installing it opens the door to a plethora of possibilities, from running Java-based server applications to executing Java bytecode for desktop applications.

Before that, however, we want to clarify the different editions and versions of Java to be as helpful and informative as possible and give you as clear an understanding as possible of each of the steps in this guide.

Differences Between OpenJDK and OpenJRE

OpenJDK and OpenJRE are related but, at the same time, distinct software components used in the Java development and execution environment. Here are the key differences between the two:

  1. OpenJDK is an open-source Java SE (Standard Edition) platform implementation. It includes a Java Development Kit (JDK), which provides tools for developing and compiling Java applications, and a Java Runtime Environment (JRE), which is necessary for running Java applications on a user’s computer.
  2. OpenJRE is a runtime environment for Java applications. It includes the Java Virtual Machine (JVM), the engine that runs Java code, and the Java class libraries, which provide the core functionality of the Java platform. OpenJRE does not include the development tools and compilers that are part of the JDK.

In summary, OpenJDK is a complete Java development and runtime environment, while OpenJRE is a runtime environment only. The JDK component of OpenJDK includes the JRE component but not vice versa.

Therefore, if you are developing Java applications, you will need the OpenJDK, while if you want only to run Java-based ones, the OpenJRE is sufficient.

Install Java on Debian 12 (Bookworm)

Although Java 11 LTS is now the most widely used version, followed closely by Java 8 LTS, looking ahead and following Oracle’s guidance, Java 17 LTS is the way to go. Fortunately, this is precisely the version available in Debian 12’s repositories.

Step 1: Check If Java Is Already Installed

First, ensure Java is not already installed on your Debian system. Type the following:

 Check if Java Is already installed on your Debian 12 system.
Check if Java Is already installed on your Debian 12 system.

If you get a message like the one shown above, “java: command not found,” your system has not yet added support for Java, so let’s proceed with its installation.

Step 2: Install OpenJDK on Debian 12

For clarity, we shall state right away that Debian provides the “default-jdk” meta-package, a regularly updated one to ship the latest version of the current OpenJDK LTS release for the convenience of its users.

So, using the APT command below will install OpenJDK 17 LTS on your Debian 12 (Bookworm) system.

sudo apt install default-jdkCode language: JavaScript (javascript)
Install OpenJDK 17 on Debian 12 (Bookworm).
Install OpenJDK 17 on Debian 12 (Bookworm).

By installing the “default-jdk” package, you get both OpenJDK 17 and OpenJRE 17 installed on your system simultaneously.

However, if you only want to install only OpenJDK, you can achieve this by running:

sudo apt install openjdk-17-jdk

Similarly, if you want to install only the JRE engine, the command you need is:

sudo apt install openjdk-17-jre

Step 3: Verify the Installation

With the command provided below, verify that the installation was successful. It should output similar to the following:

java -version
Check the installed Java version.
Check the installed Java version.

As you can see from the command’s output, we now have OpenJDK 17 successfully installed on our Debian 12 system.

Set JAVA_HOME Environment Variable

The JAVA_HOME variable is used by various applications, such as development environments and build tools, to locate the Java binaries and libraries.

When JAVA_HOME is set, the system knows where to look for the JDK and can use it to execute Java applications or compile Java code. So, open the “/etc/environment” file with the terminal text editor you are using:

sudo nano /etc/environment

Then, add in it the line:

JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"Code language: JavaScript (javascript)
Set JAVA_HOME environment variable.
Set JAVA_HOME environment variable.

Finally, apply the changes and verify everything is correct by running the two commands below.

source /etc/environment
echo $JAVA_HOMECode language: PHP (php)
Check the JAVA_HOME environment variable.
Check the JAVA_HOME environment variable.

As we can see from the echo command output, the JAVA_HOME environment variable is set correctly. Therefore, executing the command below should produce an output like the one shown.

ls -l $JAVA_HOMECode language: PHP (php)
Check the JAVA_HOME environment variable.
Check the JAVA_HOME environment variable.

Uninstall Java on Debian 12

If you want to remove Java from your Debian 12 system for any reason, first use the command below to find out all locally installed Java packages.

sudo dpkg -l | grep 'jdk\|jre'Code language: JavaScript (javascript)
Uninstall Java from Debian 12.
Uninstall Java from Debian 12.

Then pass them as names after the “sudo apt purge” command. In our case, it would look like this:

sudo apt purge default-jdk default-jdk-headless default-jre default-jre-headless openjdk-17-jdk openjdk-17-jdk-headless openjdk-17-jre openjdk-17-jre-headlessCode language: JavaScript (javascript)
Uninstall Java from Debian 12.
Uninstall Java from Debian 12.

Finally, clean your Debian system of any remaining dependencies.

sudo apt autoremove --purge

Don’t forget to remove the JAVA_HOME variable from the “/etc/environment” file by simply opening it and deleting the line that contains it.


As you can see, installing Java on Debian 12 (Bookworm) is a straightforward process that opens up a world of possibilities for developers and users alike.

Java’s cross-platform compatibility, robustness, and rich standard library make it an indispensable tool for many applications and services.

As you venture into the world of Java programming on Debian 12, remember to keep your Java installation up to date to ensure compatibility with the latest features and security patches.

Regularly updating your packages with the APT package manager or setting up automatic updates on your Debian system will guarantee that you have access to the latest versions and bug fixes.

Thanks for your time! I hope you find this guide helpful. Your feedback and comments are most welcome.

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

The average score is 68%