Easy Steps To Install OpenJDK 19 on Debian 11

In this guide, we want to show you to Install OpenJDK 19 on Debian 11. OpenJDK is an open-source version of the Java development kit. The Java development kit is a key resource for applications utilizing the Java platform. As a key Java tool, OpenJDK is extremely useful in a software development context and relatable to the diverse tech stacks that developers work with as they innovate Java-based apps, features, and microservices.

Now proceed to the guide steps below on the Orcacore website to Install Java 19 on Debian 11.

Steps To Install OpenJDK 19 on Debian 11

To Install OpenJDK 19 on Debian 11, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Debian 11.

Install Java 19 on Debian 11

First, you need to update your local package index with the command below:

sudo apt update 

Download OpenJDK 19

At this point, you need to visit the JDK Downloads page to download the latest archive by using the wget command:

sudo wget https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_linux-x64_bin.tar.gz

Then, extract your downloaded file with the command below:

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

Next, move your extracted file to the /opt directory:

sudo mv jdk-19.0.2 /opt/

Configure Java 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/jdk19.sh <<EOF
export JAVA_HOME=/opt/jdk-19.0.2
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

Source your profile file with the following command:

source /etc/profile.d/jdk19.sh

Verify your Java Home path:

echo $JAVA_HOME
Output
/opt/jdk-19.0.2

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

java -version
OpenJDK 19 on Debian 11

Test Java 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 content 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:

java HelloWorld.java
Output
Hello, World

That’s it, you are done.

Conclusion

At this point, you have learned to Install OpenJDK 19 on Debian 11. By following the guide steps to update your system, download, and install OpenJDK 19, you can quickly start using the latest Java features. Debian 11 is a stable system, and with OpenJDK 19, you have a reliable setup for developing and running Java programs effectively.

Hope you enjoy it. You may also like these articles:

Install Pritunl VPN Server and Client on Debian 11

Install and Use Yarn on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!