How to Install Java on Debian 11

Install Java on Debian 11

In this article, we will have explained the necessary steps to install Java on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Java is a high-level, robust, object-oriented, and secure programming language. The main difference between Oracle JDK and OpenJDK is that OpenJDK is free for all while Oracle Java Development Kit or Oracle JDK requires a commercial license. JDK 17 is finally out and was released on 14, September 2021 with lots of new features on the table. It is the latest LTS version of OpenJDK by the time of publishing this tutorial.

Install Java on Debian 11

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade

Step 2. Install Java 17 on the Debian system.

Now we will install default open JRE and JDK versions:

sudo apt install openjdk-17-jre openjdk-17-jdk
sudo apt-cache policy openjdk-17-jre openjdk-17-jdk

Check Java is already installed or not using the following command:

java -version

Step 3. Configuring the Environment Variable.

Once the above steps are successfully completed, we need to set the “JAVA_HOME” and “PATH” environment variables. Enter the following commands to set your environment variables:

sudo update-alternatives --config java

Output:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java is the installation path of path of OpenJDK 11
/usr/lib/jvm/java-17-openjdk-amd64/bin/java is the installation path of path of OpenJDK 17

Next, open a new environment:

sudo nano /etc/environment

Add the following file:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk

Apply the change, run the following command:

sudo source /etc/environment

Next, verify the path variable:

echo $JAVA_HOME

That’s all you need to do to install Java on Debian (Bullseye). I hope you find this quick tip helpful. For further reading Java programming language on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.