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:
- 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.
- 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:
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-jdk
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:
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
JAVA_HOME variable is used by various applications, such as development environments and build tools, to locate the Java binaries and libraries.
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:
Finally, apply the changes and verify everything is correct by running the two commands below.
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_HOME
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'
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-headless
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.