How to Install JDK on AlmaLinux

Installation

By Mayuri Fakirpure

Updated on Feb 10, 2024

In this tutorial, we'll explain how to install JDK on AlmaLinux (Java Development Kit). We will cover Installation of Oracle JDK as well as OpenJDK.  Also we will check the difference between JDK and JRE.

Prerequisites:

  • A AlmaLinux installed system.
  • User with administrative privileges. 
  • Basic Linux command knowledge.

Information

Before we proceeding with the installation, let us brifly explain the difference between JDK and JRE.

JDK

JDK stands for Java Development Kit. It is basically used for Java application development and applets. It contains Java Runtime Environment(JRE) and other development tools like an interpreter, compiler, archiver, and a document generator. If we want to test our Java application on different version of JDK, we can install different version of JDK on the same system and test it.

JRE

JRE stands for Java Runtime Environment. It is for running the Java application. It implements Java Virtual Machine(JVM). JVM is the heart of Java programming and provides platform independence. JRE doesn't doen't contain any development tools like interpreter, compiler, or debugger, etc. It is usable if we want to run only Java application and not develop the application.

So as per our requirement, we can install either JDK or JRE. For this demonstration purpose, we are installing JDK 21 but feel free to install JRE with any version you want.

Update Packages

First, Keep the system up-to-date to make sure that we have the latest version of the repository listing.

sudo dnf update

There are two ways to install Java on Ubuntu. Oracle JDK and OpenJDK. Both are the same build. The main difference is OpenJDK is an open source project that is maintained by Oracle, Redhat, and the community. Oracle JDK is required commercial license and it is maintained by Oracle. Result of that some features aren't availble with OpenJDK. But OpenJDK works very well. From JDK 17, binaries are free to use in production at no cost. You can check the official website to learn more about it. Visit Oracle JDK official website and OpenJDK official website.

1. Install Oracle JDK

To install Oracle JDK, we need to download it from Oracle official website it doesn't allow automatic installation through package manager. Here yo ucan find Linux based installer files. Download x64 RPM Package

Currently, there are 2 LTS version available JDK 21 and JDK 17. You can download as per your requirements. For this demostration purpose, we are installing JDK 21 which is latest version.

Execute following command to download JDK 21:

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

If the wget command is not found, You can install it using this command: sudo dnf install wget. Once the download gets completed, install it using dpkg command:

sudo rpm -ivh jdk-21_linux-x64_bin.rpm

verify the installation by checking the version:

java --version

This command should display information about the installed Java version.

java 21.0.2 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 21.0.2+13-LTS-58)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode, sharing)

We have successfully installed Oracle JDK 21.

2. Install OpenJDK

Ubuntu repositories typically include OpenJDK. It is an open-source implementation of the Java Platform. We can install default version of the JDK which is 11 or we can install the specific version. 

For this demostration purpose, we are installing JDK 21. If you have any specific version requirement, replace 21 from following command with your version.

dnf install java-21-openjdk-devel -y

After the installation is complete, we can verify that Java has been installed correctly by checking the version:

java --version

This command should display information about the installed Java version.

openjdk 21.0.2 2024-01-16 LTS
OpenJDK Runtime Environment (Red_Hat-21.0.2.0.13-1) (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.2.0.13-1) (build 21.0.2+13-LTS, mixed mode, sharing)

We have successfully installed OpenJDK 21.

We have seen how to install Java on AlmaLinux 8. We have learnt about OpenJDK and OpenJDK. Also the difference between JDK and JRE.

This chapter is completed succesfully.