Easy Steps To Install OpenJDK 17 on Debian 11

This tutorial intends to teach you How To Install 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 on the Orcacore website, you will learn Java 17 Download, configure the 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 download and 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 for Java 17 download the latest binary package 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 download installation on Debian 11 by checking its version:

java -version
Java 17 download installation on Debian 11

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 also interested in these articles:

How To Install PHP 8.2 on Debian 11

Set up PHP ionCube Loader on Debian 11

FAQs

What is OpenJDK?

It is an open-source Java Platform, Standard Edition (Java SE) implementation. It provides all the tools required to develop and run Java applications.

How do I verify that OpenJDK 17 has been installed?

You check your Java version: java -version

How do I set OpenJDK 17 as the default Java version?

You can use the following command to configure the default Java version:
sudo update-alternatives --config java
Then, select OpenJDK 17 from the options.

Where is OpenJDK 17 installed on Debian 11?

By default, OpenJDK is installed in /usr/lib/jvm.

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!