How to Install OpenJDK 17 on Debian 12 or 11

In the ever-evolving landscape of Java Development Kits (JDK), OpenJDK 17 stands as a pivotal long-term support (LTS) release. For those navigating the Debian ecosystem, understanding its nuances becomes imperative. This guide is tailored to illustrate how to install OpenJDK 17 on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster, drawing from the Debian default repository.

Features of OpenJDK 17:

  • Robust JDK Encapsulation: OpenJDK 17 enhances the encapsulation of JDK internals, fortifying against unwarranted access.
  • SecurityManager Deprecation: Marking a shift in security paradigms, the SecurityManager is slated for removal in upcoming releases.
  • Pattern Matching Enhancement: The ‘switch’ statement and expression witness a revamp with the integration of pattern matching.
  • JEP 356: A leap in random number generation with the introduction of new interfaces and implementations.
  • JEP 382: A novel rendering pipeline for macOS, anchored in Apple’s Metal framework.
  • JEP 389: A groundbreaking API facilitating Java program interoperability with external code and data.
  • JEP 411: The deprecation of java.lang.Object.finalize and related finalization APIs, earmarked for future removal.

Further Enhancements in OpenJDK 17:

  • JEP 391: The integration of a macOS/AArch64 port into the JDK.
  • JEP 388: The official endorsement of Windows/AArch64 support.
  • JEP 387: Enhanced memory management with the prompt return of memory to the OS, optimizing the metaspace footprint.
  • JEP 376: The Z Garbage Collector’s capability to process thread stacks concurrently.

OpenJDK 17 embodies the relentless dedication of the community to refine the JDK in alignment with industry requisites. For developers and system administrators, grasping these advancements is pivotal to architecting modern, scalable, and efficient applications.

Debian 10 Buster users, OpenJDK 17 is unavailable by default on this older stable Debian distribution release; please visit our guide on How to Install Oracle Java 17 on Debian 12/11/10 Linux.

Install OpenJDK 17 on Debian 12, 11, or 10 via APT

Step 1: Update Debian Packages Before OpenJDK 17 Installation

Before installing OpenJDK, it is imperative to ensure that all system packages on your Debian Linux are up to date. Updating the system minimizes the chances of running into conflicts during the OpenJDK installation process. Execute the command below in your terminal to update and upgrade the packages:

sudo apt update && sudo apt upgrade

This command fetches the list of available updates and then upgrades the packages.

Step 2: Search for OpenJDK 17 Packages

The most reliable and hassle-free method to install OpenJDK 17 is through the default Debian repository. Debian repositories usually contain many software packages that are compatible and well-tested with Debian. To search for the OpenJDK 17 packages, run this command:

apt-cache search openjdk | grep openjdk-17

This command filters out the available OpenJDK 17 packages in the repository.

Screenshots showcasing the process of listing OpenJDK 17 on a Debian Linux system.
Visual demonstration of how OpenJDK 17 appears when listed on Debian Linux.

Install the OpenJDK 17 JRE and JDK on Debian

Depending on your version of Debian, the next step is to install the OpenJDK 17 JDK (Java Development Kit) and JRE (Java Runtime Environment) if they are available in your distribution repository. Use the following commands:

sudo apt install openjdk-17-jre
sudo apt install openjdk-17-jdk

JDK is used for developing Java applications, whereas JRE is used for running them.

Confirm the Installation of OpenJDK 17

Now, it’s essential to ensure that OpenJDK was installed successfully. This can be done by checking the version of Java installed on your system with the command:

java --version

Handling Updates and Removal for OpenJDK 17

Debian Linux facilitates the straightforward handling of updates via the standard apt update and apt upgrade commands. If, for any reason, you decide to uninstall JDK or JRE, you can do so by executing the following command:

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

This will not only uninstall the packages but also remove any lingering dependencies and data related to them.

Switching Between Java Versions on Debian Linux

After installing OpenJDK 17 on your Debian system, there may be scenarios where you need to switch between different versions of Java. This is particularly relevant if you work on multiple projects requiring different Java versions. Debian Linux provides a simple and effective mechanism to manage and switch between different Java versions using the update-alternatives command.

Listing Available Java Versions

To begin with, it’s essential to know which Java versions are installed on your system. By running the update-alternatives command with the --config option, you can see a list of all the Java versions available on your system.

sudo update-alternatives --config java

If multiple versions are installed, you will see a list of Java versions, each with a unique number.

Selecting a Different Java Version

To switch to a different Java version, enter the corresponding number from the list and press the enter key. For instance, if Java 11 is listed with “1”, you would type “1” and press enter. You should then see a confirmation message indicating that the switch was successful:

update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode

This message tells you that the system uses Java 11 to execute Java programs.

Verifying the Current Java Version

After switching, confirming that the Java version has been updated successfully is good practice. You can do this by running the java command with the --version option:

java --version

This command displays the currently active Java version. If it reflects the version you switched to, you have successfully changed the Java version on your Debian Linux system.

Switching Back or to Another Version

Repeat the steps outlined above to switch back to a different Java version. Select the number corresponding to the desired Java version from the list presented by the update-alternatives command.

Remember that managing different Java versions effectively is crucial for the smooth execution of Java applications and the development process, especially when working with various projects that rely on different versions of the Java Development Kit (JDK).

Conclusion

This guide delved into the detailed steps for installing OpenJDK 17 on Debian Linux. Moreover, we looked into how to switch between different Java versions seamlessly, which is imperative for developers juggling multiple projects. As OpenJDK is essential for running Java applications, ensuring it is installed correctly is crucial.

Leave a Comment


Your Mastodon Instance
Share to...