Debian

How to Install Java OpenJDK and OpenJRE on Debian 12

OpenJDK is the open-source version of the Java Development Kit. OpenJRE is the open-source version of the Java Development Environment.

OpenJDK is used to compile the Java source code and test the Java programs. OpenJRE is used to run the compiled Java programs. So, if you’re a Java Developer or you want to learn Java on Debian 12, you might want to install OpenJDK on Debian 12. If you just want to run the Java programs on Debian 12, installing just OpenJRE is enough.

In this article, we will show you how to install Java OpenJDK and OpenJRE on the Debian 12 desktop. We will also show you how to install Java OpenJDK and OpenJRE on the Debian 12 headless server.

NOTE: If you’re looking to install the Oracle Java Development Kit (JDK) on Debian 12, read the article on How to Install Oracle Java Development Kit (JDK) on Debian 12.

Topic of Contents:

  1. Updating the Debian 12 Package Database Cache
  2. Installing Java OpenJDK on Debian 12
  3. Checking Whether OpenJDK Is Installed Correctly on Debian 12
  4. Installing the Java OpenJRE on Debian 12
  5. Checking Whether OpenJRE Is Installed Correctly on Debian 12
  6. Conclusion

Updating the Debian 12 Package Database Cache

First, update the APT package database cache of Debian 12 with the following command:

$ sudo apt update

A screenshot of a computer Description automatically generated

Installing Java OpenJDK on Debian 12

If you’re a Java developer or you want to learn to Java program – you want to write the Java programs, compile them, and test them on Debian 12 – you need to install OpenJDK on Debian 12.

On Debian 12, you can install either the full version of OpenJDK or the headless version of OpenJDK. The full version of OpenJDK comes with Java GUI programming libraries and can run the graphical Java apps as well. The headless version of OpenJDK works with only the command-line Java apps. If you’re using a Debian 12 desktop environment, install the full version of OpenJDK. If you’re using a Debian 12 headless server, install the headless version of OpenJDK.

To install the full version of OpenJDK on Debian 12 desktop, run the following command:

$ sudo apt install openjdk-17-jdk

To install the headless version of OpenJDK on Debian 12 server, run the following command:

$ sudo apt install openjdk-17-jdk-headless

To confirm the installation, press Y and then press <Enter>.

A screenshot of a computer program Description automatically generated

OpenJDK and all the required dependency packages are being downloaded from the internet. It takes a few seconds to complete.

A screenshot of a computer Description automatically generated

OpenJDK and all the required dependency packages are being installed. It takes a few seconds to complete.

A screenshot of a computer program Description automatically generated

At this point, OpenJDK should be installed on Debian 12.

A screenshot of a computer Description automatically generated

Checking Whether OpenJDK Is Installed Correctly on Debian 12

Once OpenJDK is installed, run the following commands to check whether you can access OpenJDK:

$ javac --version

$ java --version

As you can see, the OpenJDK compiler version 17 and OpenJDK runtime environment version 17 are installed on our Debian 12 machine.

A screenshot of a computer Description automatically generated

Installing Java OpenJRE on Debian 12

If you just want to run the Java programs on Debian 12, you need to have OpenJRE installed on your Debian 12 machine.

If you want to run the Java GUI programs on your Debian 12 desktop, you have to install the full version of OpenJRE. If you want to run only the Java command-line programs on your Debian 12 headless server, you can install the headless version of the OpenJRE.

To install the full version of OpenJRE on your Debian 12 desktop, run the following command:

$ sudo apt install openjdk-17-jre

To install the headless version of OpenJRE on your Debian 12 headless server, run the following command:

$ sudo apt install openjdk-17-jre-headless

To confirm the installation, press Y and then press <Enter>.

A screenshot of a computer program Description automatically generated

OpenJRE and all the required dependency packages are being downloaded from the internet. It takes a few seconds to complete.

A screenshot of a computer Description automatically generated

OpenJRE and all the required dependency packages are being installed. It takes a few seconds to complete.

A screenshot of a computer Description automatically generated

At this point, OpenJRE should be installed on Debian 12.

A screenshot of a computer Description automatically generated

Checking Whether OpenJRE Is Installed Correctly on Debian 12

Once OpenJRE is installed, run the following command to check whether you can access OpenJRE:

$ java --version

As you can see, the Java runtime environment version 17 is installed on our Debian 12 machine.

Conclusion

We showed you how to install Java OpenJDK and OpenJRE on the Debian 12 desktop. We also showed you how to install Java OpenJDK and OpenJRE on the Debian 12 headless server.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.