Home  »  ArticlesGuidesHardwareHow ToLibrariesProgrammingTechnology   »   How to Install Java 22 (JDK 22) on AlmaLinux 8.10 Systems

How to Install Java 22 (JDK 22) on AlmaLinux 8.10 Systems

Java Development Kit (JDK) 22 is the latest version of the Java Platform, offering new features and improvements for developers. This guide will walk you through the steps to install JDK 22 on an AlmaLinux 8.10 system.

Prerequisites

Before you begin, ensure you have:

  • A running AlmaLinux 8.10 system
  • A user account with sudo privileges
  • Internet connectivity to download necessary packages

Step 1: Update Your System

First, update your system to ensure all existing packages are up to date.

$ sudo dnf update -y

Step 2: Download JDK 22

Download the JDK 22 package from the official Oracle website. At the time of writing, JDK 22 is the latest version available.

Visit the Oracle JDK Downloads page and download the RPM package. Alternatively, you can use the following command to download the RPM directly (replace the URL with the latest version if necessary):

$ wget https://download.oracle.com/java/22/latest/jdk-22_linux-x64_bin.rpm

Step 3: Install JDK 22

Install the downloaded JDK 22 RPM package using the dnf package manager.

$ sudo dnf localinstall jdk-22_linux-x64_bin.rpm

Step 4: Verify the Installation

To verify that JDK 22 has been installed correctly, check the Java version.

$ java -version

You should see output similar to this, indicating the installed version of Java:

java version "22"
Java(TM) SE Runtime Environment (build 22+36-2345)
Java HotSpot(TM) 64-Bit Server VM (build 22+36-2345, mixed mode)

Step 5: Set Up Java Environment Variables

Setting up environment variables ensures that Java applications can find the JDK installation.

Open Profile File

Open the profile file to add the environment variables.

$ sudo nano /etc/profile.d/jdk.sh

Add the Following Lines

Add the following lines to set up the JAVA_HOME environment variable and update the PATH.

$ export JAVA_HOME=/usr/java/jdk-22
$ export PATH=$PATH:$JAVA_HOME/bin

Apply the Changes

Save the file and apply the changes.

$ source /etc/profile.d/jdk.sh

Step 6: Verify Environment Variables

To ensure the environment variables are set correctly, check the JAVA_HOME and PATH variables.

$ echo $JAVA_HOME
$ echo $PATH

You should see output that includes the path to your JDK 22 installation.

Step 7: Test the Installation

Create a simple Java program to test your JDK installation.

Create a Java Program

Create a file named HelloWorld.java.

$ nano HelloWorld.java

Add the following content to the file:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Compile the Java Program

Compile the Java program using the javac command.

$ javac HelloWorld.java

Run the Java Program

Run the compiled Java program.

$ java HelloWorld

You should see the output:

Hello, World!

Conclusion

You have successfully installed JDK 22 on your AlmaLinux 8.10 system. Java is now ready for you to start developing robust and scalable applications. For more detailed information and advanced usage, refer to the official Java documentation.

Happy coding!

References

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.