2 ways to install OpenJDK 11 on Debian 12 Server or Desktop

OpenJDK 11 is the open-source edition of the Oracle standard Java Platform that is available to install on almost all Linux systems using their default system repository. It is released under the GNU license and is extremely important if you plan to install some application that requires JAVA or want to start developing applications in the JAVA programming language. Apart from the open source license, the LTS ( long-term support) versions of OpenJDK offer stability and longevity, thus making it a preferable choice for enterprise implementation where the long-term reception of security patches and updates is essential. Although a newer version of OpenJDK is already available, if you need to pick up and install version 11 on Debian 12 Linux, then this tutorial can help you.

System Requirements

There are no special requirements for installing OpenJDK 11 on Debian 12. You need access to the terminal, a user with sudo rights, and an active internet connection for downloading and updating packages.

Carry out the System Update.

Installing packages using locally available Debian binary would not create any issues. Still, when we want to use the APT package manager to fetch packages from the remote repositories, we should start with the system update. It not only rebuilds the APT package index cache but also installs the latest system updates. Hence, run the given command:

sudo apt update

Those who want to install the upgrades for existing packages can also run the given command if available.

sudo apt upgrade

Download OpenJDK Tarball file

In this method, instead of installing the OpenJDK 11 using some repository, we will download its tarball file containing the required executable and other files.

Install Wget:

sudo apt install wget

Download OpenJDK 11:

wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz

Installing OpenJDK by setting up its directory

Extract the downloaded .tar.gz file.

tar -xzf openjdk-11+28_linux-x64_bin.tar.gz

Move the extracted files to the /opt directory (or another directory of your choice).

sudo mv jdk-11 /opt/

Set Up Environment Variables:

Set up environment variables to use the newly installed JDK. You can do this by adding the following lines to your .bashrc or .profile file:

echo "export JAVA_HOME=/opt/jdk-11" >> ~/.bashrc
echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> ~/.bashrc

Then, reload your profile:

source ~/.bashrc

Verify that the installation was successful by checking the Java version:

java -version

You should see output similar to this:

Note: If you have multiple versions of OpenJDK installed, check out the last step, which discussed – how to use “Update-alternatives” for JAVA.

openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

Adding SID repository with preference

Well, OpenJDK 11 is unavailable through the default system repositories of Debian 12; instead, version 17 is there. However, we can install OpenJDK 11 by adding the Debian SID repository, which is meant to install the latest packages for testing. Also, to stop this repo from installing the latest untested packages automatically, we will create a preference file.

  • First, edit the “sources.list” file and add the following line at the end of the file:
sudo nano /etc/apt/sources.list
  • In the file, add this line:
deb http://deb.debian.org/debian unstable main non-free non-free-firmware contrib

Save the file by pressing Ctrl+O, hit the Enter key and Ctrl+X to exit

  • Set preferences for the packages:
sudo nano /etc/apt/preferences

Add the following lines. This will make our Debian 12 system only choose stable packages when updating instead of unstable ones.

Package: *
Pin: release a=stable
Pin-Priority: 900

Package: *
Pin: release a=unstable
Pin-Priority: 50

Again, save the file like we did earlier using Ctrl+O.

set package prefernces

Run system update to refresh the APT repository cache:

sudo apt update

Installing OpenJDK 11 Debian 12

The OpenJDK 11 packages are available to install through the default repositories of almost all Linux distros. However, as we know, in Debian 12, it is not available, but after adding the SID repository, we can get it like any other typical package using the APT package manager. Here is the command to follow:

sudo apt install openjdk-11-jdk
command installing OpenJDK 11 debian 12

Nevertheless, you can use the given command to check what other versions are available to install on your Debian 12.

sudo apt search openjdk

Verifying the Installation

If you have completed the installation command to get OpenJDK 11 on Debian 12, you would already have it; however, to confirm the same, we can check the JAVA version using the given command.

java --version
check Java version

Set OpenJDK 11 as the default JAVA version.

Now, we have OpenJDK 11, but what if you already have OpenJDK 17 or any other version on your Debian 12 system? How will you make any one of them the system-wide default version?

Well, if you have multiple versions of Java, we can use the Update-alternatives command to manage them.

sudo update-alternatives --config java

You will see the list of all Java versions installed on your Debian 12 system, now to set the one as the default enter the Selection number of that and hit the Enter key.

For example, we have JAVA 17 as the default version, but we want that to be JAVA 11, so we will enter the selection number—1 and press the Enter key.

Similarly, in the future, if we want to revert to Java 17, we rerun the Update-alternatives command to select it.

Set OpenJDK 11 as the default in Debian 12

OpenJDK 11 Uninstallation (optional)

In the future, if you have completed your project and don’t need Java 11 anymore on your Debian 12 system, then you can delete it using the given command:

sudo apt remove openjdk-11*

Conclusion

Installing OpenJDK 11 on Debian can significantly enhance your Java development environment. Following the detailed instructions in this guide will give you the open-source Java 11 without facing any significant problems. If you have, let us know by using the comment section.

Frequently Asked Questions (FAQs)

  1. How do I switch between different Java versions installed on my Debian system? Switching between different Java versions is relatively easy and can be achieved using the sudo update-alternatives –config java command. It will display a list of installed Java versions; we need to enter the selection number of the corresponding version we want to set as the default.
  2. Is OpenJDK 11 suitable for use in enterprise-level applications and development? Yes, OpenJDK 11 is well-suited for enterprise-level applications. Its Long-Term Support (LTS) status ensures stability and ongoing updates, making it a reliable choice for businesses.
  3. Can I install OpenJDK 11 alongside other Java versions?
    Yes, we can install OpenJDK 11 alongside other Java versions. Debian to any other Linux will allow multiple Java installations, and the good thing is that we can switch between them using the update-alternatives command.
  4. What is the critical difference between OpenJDK 11 and Oracle JDK?
    The primary difference is in licensing and support. OpenJDK 11 is open-source and free, while Oracle JDK may require a commercial license for specific uses. Both offer similar performance and features, but OpenJDK is generally preferred for open-source projects.

2 thoughts on “2 ways to install OpenJDK 11 on Debian 12 Server or Desktop”

  1. Doesn’t work:
    The following packages have unmet dependencies:
    libpng16-16t64 : Breaks: libpng16-16 (= 2.38) but 2.36-9+deb12u7 is to be installed
    Depends: libasound2t64 (>= 1.0.16)
    openjdk-11-jre-headless : Depends: libc6 (>= 2.38) but 2.36-9+deb12u7 is to be installed
    Recommends: libcups2t64 but it is not going to be installed
    Recommends: libasound2t64 (>= 1.0.16)
    E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.