How to Install OpenJDK 17 on Debian 11 Bullseye

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.

The tutorial will look at installing the OpenJDK version instead of the default Oracle JDK. The difference between these two is licensing. OpenJDK is an entirely free open-source Java with a GNU General Public License, and Oracle JDK requires a commercial license under the Oracle Binary Code License Agreement. Other differences are release schedules and other factors that come into play; however, performance is pretty much the same.

In the following tutorial, you will learn how to install the latest OpenJDK 17 LTS on Debian 11 Bullseye.

Advertisement

Prerequisites

Update Operating System

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

sudo apt update && sudo apt upgrade -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@debian~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on Adding a User to Sudoers on Debian.

To use the root account, use the following command with the root password to log in.

su

The tutorial will utilize the terminal for the installation found in Activities > Show Applications > Terminal.

Example:

How to Install OpenJDK 17 on Debian 11 Bullseye

Option 1. Install OpenJDK 17 with APT

The first and most recommended option is to install OpenJDK using the default Debian 11 repository. First, search to find what is available.

In your terminal, use the following command.

apt-cache search openjdk

Example output:

How to Install OpenJDK 17 on Debian 11 Bullseye

As the above output states, OpenJDK 17 JDE and JRE are available to install.

To begin the installation, use the following terminal command.

Install OpenJDK 17 – JRE:

sudo apt-get install openjdk-17-jre

Install OpenJDK 17 – JDK:

sudo apt-get install openjdk-17-jdk

Confirm the installation by running the following command.

java --version

Example output:

How to Install OpenJDK 17 on Debian 11 Bullseye

Updates are handled with the standard apt update and upgrade commands. However, you can remove them separately or altogether if you no longer require JDK or JRE.

Example:

sudo apt-get remove openjdk-17-jre openjdk-17-jdk --purge

Note, this will remove any unrequited leftover dependencies and thoroughly wipe the installation and data as much as possible from your system.

Advertisement

Option 2. Install OpenJDK 17 Manually

The second option is to install OpenJDK 17 by downloading the .tar.gz archive package. This is often more up-to-date than the Debian version repository, but you will need to keep an eye on new updates and re-do the process, which can be a burden if you keep forgetting.

Download Latest Java 17 Build

Visit the downloads page to get the latest build version link, then use the following wget command.

Example:

Linux  AArch64 users:

wget https://download.java.net/java/GA/jdk17.0.1/2a2082e5a09d4267845be086888add4f/12/GPL/openjdk-17.0.1_linux-aarch64_bin.tar.gz

Linux  x64 users (Majority of users):

wget https://download.java.net/java/GA/jdk17.0.1/2a2082e5a09d4267845be086888add4f/12/GPL/openjdk-17.0.1_linux-x64_bin.tar.gz

Once the download is complete, you need to extract the archive.

tar -xvf openjdk-17.0.1_linux-{version number}

Example:

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

Remember, in future versions, and the file name will change, a quick method is to type OpenJDK-17 then press your TAB key to complete the file name.

Configure and Install OpenJDK 17

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

sudo mv jdk-17.0.1 /opt/

Now you need to set the environment variables, copy and paste the below into your terminal.

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

Remember, change jdk-17.0.1 with the current directory name if you want it or have future updated versions.

To confirm the installation, run the following command.

java --version
echo $JAVA_HOME

If installed correctly, you should see the following output:

How to Install OpenJDK 17 on Debian 11 Bullseye

As you can see, you can see the version is the latest OpenJDK 17 build. Remember, you must check back and re-do the process for future updates.

Ideally, you may want to run this anyway. If not, keep this in mind.

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 test using the famous Hello World example.

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 OpenJDK 17 on Debian 11 Bullseye

Congratulations, everything is working correctly.

Comments and Conclusion

In the tutorial, you have learned how to download and install OpenJDK 17 latest version by learning two methods, 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