Easy Steps To Install OpenJDK 19 on Debian 11 – OrcaCore

Posted on

Easy Steps To Install OpenJDK 19 on Debian 11 - OrcaCore

Easy Steps To Install OpenJDK 19 on Debian 11 – OrcaCore

This guide provides a comprehensive walkthrough on how to Install OpenJDK 19 on Debian 11. OpenJDK, the open-source implementation of the Java Development Kit (JDK), is an indispensable tool for developers working with the Java platform. Its versatility makes it relevant across diverse tech stacks, empowering innovation in Java-based applications, features, and microservices. Successfully Install OpenJDK 19 on Debian 11 and unlock the power of the latest Java features.

Now, let’s delve into the step-by-step instructions to Install OpenJDK 19 on Debian 11 as presented on the Orcacore website.

Install OpenJDK 19 Debian 11

Before proceeding, ensure you are logged into your Debian 11 server as a non-root user with sudo privileges. Refer to the Orcacore guide on Initial Server Setup with Debian 11 if needed.

First, refresh your local package index:

sudo apt update

Download OpenJDK 19

Navigate to the JDK Downloads page and obtain the latest archive link. Use the wget command to download the archive:

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

Extract the downloaded archive:

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

Move the extracted directory to the /opt directory:

sudo mv jdk-19.0.2 /opt/

Configure Java Environment Path on Debian 11

Set the JAVA_HOME environment variable:

sudo tee /etc/profile.d/jdk19.sh <<EOF
export JAVA_HOME=/opt/jdk-19.0.2
export PATH=$PATH:$JAVA_HOME/bin
EOF

Source the profile file:

source /etc/profile.d/jdk19.sh

Verify the JAVA_HOME path:

echo $JAVA_HOME
OpenJDK 19 Debian 11

Confirm the Java 19 installation by checking the version:

java -version
OpenJDK 19 on Debian 11

Test Java Installation on Debian 11

Create a sample Java project to validate the installation.

Create and open a file named HelloWorld.java using a text editor (like vi):

vi HelloWorld.java

Add the following code:

public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}

Save and close the file.

Compile and run the Java code:

javac HelloWorld.java
java HelloWorld
**Output**
Hello, World

You have successfully Install OpenJDK 19 on Debian 11!

Conclusion

This guide detailed the steps required to Install OpenJDK 19 on Debian 11. By updating your system, downloading, and installing OpenJDK 19, you are now equipped to utilize the latest Java features on a stable Debian 11 system.

Alternative Installation Methods

While the previous method involves manual download and configuration, alternative methods exist that can streamline the installation process of OpenJDK 19 on Debian 11. Here are two such approaches:

1. Using SDKMAN! (Software Development Kit Manager)

SDKMAN! is a versatile tool for managing multiple software development kits, including Java. It simplifies the installation, management, and switching between different JDK versions.

Explanation:

SDKMAN! provides a command-line interface to discover, install, and manage different JDK distributions. It handles the download, extraction, and environment configuration automatically, minimizing manual intervention. This is particularly helpful for developers who need to work with multiple Java versions simultaneously.

Steps:

  1. Install SDKMAN!:

    curl -s "https://get.sdkman.io" | bash
    source "$HOME/.sdkman/bin/sdkman-init.sh"

    Follow the on-screen instructions to complete the installation. You may need to open a new terminal or source the sdkman-init.sh file.

  2. List Available JDKs:

    sdk list java

    This command displays a list of available JDKs, including different OpenJDK distributions and versions.

  3. Install OpenJDK 19:

    Identify the appropriate OpenJDK 19 distribution from the list and use its identifier to install it. For example, if the identifier is 23.0.0.ea.34-open, the command would be:

    sdk install java 23.0.0.ea.34-open

    Replace 23.0.0.ea.34-open with the actual identifier from the list. SDKMAN! will download, install, and configure the environment for you.

  4. Set as Default (Optional):

    To make OpenJDK 19 the default Java version:

    sdk default java 23.0.0.ea.34-open

    Again, replace 23.0.0.ea.34-open with the actual identifier.

  5. Verify installation:
java -version

2. Using a Third-Party Repository (e.g., Adoptium/Eclipse Temurin)

While Debian’s default repositories may not always have the latest OpenJDK versions readily available, adding a third-party repository specifically for Java distributions, such as Adoptium (formerly AdoptOpenJDK) which provides Eclipse Temurin builds, can simplify the process.

Explanation:

Adoptium provides pre-built binaries of OpenJDK that are easily installable through package managers like apt. By adding the Adoptium repository to your system, you can install OpenJDK 19 using the familiar apt install command. This leverages Debian’s package management system for seamless installation and updates.

Steps:

  1. Add the Adoptium Repository:

    First, download and install the Adoptium public key:

    wget -O /tmp/adoptium.asc https://packages.adoptium.net/artifactory/api/gpg/key/public
    sudo apt-key add /tmp/adoptium.asc

    Next, add the repository to your sources.list:

    sudo tee /etc/apt/sources.list.d/adoptium.list <<EOF
    deb https://packages.adoptium.net/artifactory/debian/ $(awk -F '=' '/^VERSION_CODENAME=/ {print $2}' /etc/os-release) main
    EOF
  2. Update Package Index:

    sudo apt update
  3. Install OpenJDK 19 (Eclipse Temurin):

    sudo apt install temurin-19-jdk
  4. Verify installation:

java -version

These methods offer alternative, often simpler, ways to install OpenJDK 19 on Debian 11, leveraging package managers or dedicated SDK management tools. The SDKMAN! method is especially useful when needing to manage multiple Java versions. Adoptium is a good option if you want OpenJDK managed through apt, similar to system packages. They both abstract away the manual steps involved in downloading, extracting, and configuring the environment.

Leave a Reply

Your email address will not be published. Required fields are marked *