How To Install OpenJDK 17 on Debian 11

This tutorial intends to teach you to How To Install Java OpenJDK 17 on Debian 11.

OpenJDK is a powerful, free, and open-source implementation of Java. OpenJDK is another app that you can use instead of Oracle JDK because it is free and high-performance.

In this article, you will learn to download Java JDK 17 and configure your environment path on Debian 11, and test your Java 17 installation by creating a sample project.

Note: We have other guides that include the Java installation on different OS which are as follows:

Set up OpenJDK 17 on Ubuntu 20.04

How To Install OpenJDK 17 on AlmaLinux 9

How To Install OpenJDK 17 on Centos 7

How To Install OpenJDK 17 on Debian 11?

To complete this guide, you must have access to your server as a non-root user with sudo privileges. For this purpose, you can follow this guide on Initial Server Setup with Debian 11. Now follow the steps below to start your Java 17 installation:

Step 1 – Download OpenJDK 17 Binary Package

First, you must run the system update with the following command:

sudo apt update

Then, you need to visit the JDK Downloads page to download the latest binary package for Java 17 by using the wget command:

sudo wget https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz

Next, extract your downloaded file with the command below:

sudo tar xvf openjdk-17.0.2_linux-x64_bin.tar.gz

Now move your extracted file to the /opt directory:

sudo mv jdk-17.0.2 /opt/

Step 2 – Configure Java 17 Environment Path on Debian 11

At this point, you need to configure the Java home path by using the following command:

sudo tee /etc/profile.d/jdk17.sh <<EOF
export JAVA_HOME=/opt/jdk-17.0.2
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

Source your profile file with the following command:

source /etc/profile.d/jdk17.sh

Verify your Java Home path:

echo $JAVA_HOME
Output
/opt/jdk-17.0.2

Also, you can verify your Java 17 installation on Debian 11 by checking its version:

java -version
Output
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

Step 3 – Test Java 17 Installation on Debian 11

At this point, we will show you to create a sample project to see that your Java is working correctly on Debian 11.

Create and open the hello world file with your favorite text editor, here we use the vi editor:

vi HelloWorld.java

Add the following Java code to the file:

public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}

When you are done, save and close the file.

Then, compile and run your Java code with the following command:

java HelloWorld.java
Output
Hello, World

That’s it, you are done.

Conclusion

At this point, you have learned to download the JDK 17 binary package and configure the environment path for Java and test your installation by creating a sample Hello World project.

Hope you enjoy it. You may be interested in these articles too:

How To Install PHP 8.2 on Debian 11

Set up PHP ionCube Loader on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Stay informed and not overwhelmed, subscribe now!