How to Install Java 16 (OpenJDK 16) on Debian 11

Java is a general-purpose, class-based, object-oriented multipurpose programming language that is popular due to the design of having lesser implementation dependencies, meaning that the compiled Java code can be run on all platforms that support Java without the need for recompilation. Java is also fast, secure, and reliable, therefore. It is widely used for developing Java applications in laptops, data centers, game consoles, scientific supercomputers, cell phones, etc.

In the following tutorial, you will learn how to install the latest Java 16 (OpenJDK 16) on Debian 11 Bullseye.

Advertisement

Prerequisites

  • Recommended OS: Debian 11 Bullseye
  • User account: A user account with sudo privilages or root access (su command).
  • Required Packages: wget

Updating Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade

Root or Sudo Access

By default, when you create your account at startup with Debian compared to other distributions, it does not automatically receive sudoers status. You must either have access to the root password to use the su command or visit our tutorial on How to Add a User to Sudoers on Debian.

Install CURL Package

The tutorial will utilize the curl package to download the GPG key; first, verify if the package is present:

curl --version

Example output if installed:

curl 7.74.0 (x86_64-pc-linux-gnu) libcurl/7.74.0 OpenSSL/1.1.1k zlib/1.2.11 brotli/1.0.9 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.43.0 librtmp/2.3
Release-Date: 2020-12-09

If you do not have curl installed, use the following command:

sudo apt install curl -y

Install Java OpenJDK 16 – DPKG

Install Java 16

The easier option but the most restrictive is to install Java OpenJDK 16 using the dpkg command, which is a tool to install, build, remove and manage Debian packages

First, download the .deb package from Java’s download page:

Example:

How to Install Java 16 (OpenJDK 16) on Debian 11

Once installed, navigate to the directory you downloaded Java to; by default, this would be the Downloads directory:

cd /home/username/Downloads

Once you have downloaded the .deb package, run the following command in your terminal to install Java:

sudo dpkg -i jdk-16.0.2_linux-x64_bin.deb

Example output:

How to Install Java 16 (OpenJDK 16) on Debian 11

Remove Java 16

If you no longer require OpenJDK 16 and have installed the software using the .deb JDK package, you can use the following dpkg command with the -r flag option that will remove the package as the example below:

sudo dpkg -r jdk-16.0.2

Example output:

How to Install Java 16 (OpenJDK 16) on Debian 11
Advertisement

Install Java OpenJDK 16 – Manual Option

The second and most recommended option is to install OpenJDK 16, the manual way that benefits users with more freedom and power on what they want and where installed on their system.

Download Latest Java 16 Build

Visit the downloads page to get the latest build version link, then use the following curl command:

curl  -O https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_linux-x64_bin.tar.gz

Once the download is complete, you need to extract the archive as follows:

tar -xvf openjdk-16.0.2_linux-x64_bin.tar.gz

Configure and Install Java 16

Next, move the extracted archive directory into the /opt/ location:

sudo mv jdk-16.0.2 /opt/

Now you need to set the environment variables as below:

export JAVA_HOME=/opt/jdk-16.0.2
export PATH=$PATH:$JAVA_HOME/bin

Java 16 is now installed. To confirm, use the following commands:

java --version
echo $JAVA_HOME

If installed correctly, you should see the following output:

openjdk 16.0.2 2021-07-20
OpenJDK Runtime Environment (build 16.0.2+7-67)
OpenJDK 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)
/opt/jdk-16.0.2

As you can see, you can see the version is the latest 16.0.2 build.

Advertisement

Test Java – Create Hello World Application

To finish off, it is always handy to test installations of these kinds to confirm everything is working correctly after being installed. The easy way is to create a small program script to test using the famous Hello World.

First, create the Java program file as follows

sudo nano hello.java

Next, add the following Java code into the file:

public class hello {
  public static void main(String[] args) {
    System.out.println("G'day from LinuxCapable!");
  }
}

Save the file (CTRL+O), then exit (CTRL+X).

Next, compile the code:

javac hello.java

Finally, run the Java code with the following command:

java hello

Example output:

How to Install Java 16 (OpenJDK 16) on Debian 11

Congratulations, everything is working correctly.

Comments and Conclusion

In the tutorial, you have learned how to download and install Java 16 (OpenJDK 16) latest version, along with downloading and future versions and installing with the same process for your Debian 11 Bullseye operating system.

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
adplus-dvertising
0
Would love your thoughts, please comment.x
()
x