
Java 21 is the Java platform’s Long-Term Support (LTS) release. As a high-level, object-oriented, class-based programming language used for developing mobile and desktop applications, it can run on all major operating systems. Java is designed with the philosophy of:
“Write Once, Run Anywhere” (WORA) allows you to write Java code on one platform and run it on any other platform that supports the Java Virtual Machine (JVM) without modifying the source code. This tutorial will show you how to install Java 21 on AlmaLinux 10.
Table of Contents
Prerequisites
- An AlmaLinux 10 server.
- Access to the root user account (or access to an admin account with root privileges)
Step 1. Update System Packages
First, log in to your Almalinux 10 server via SSH as the root user:
Replace ‘IP_Address’ and ‘Port_number’ with your server’s IP address and SSH port number. If needed, replace ‘root’ with the username of your sudo account.
Once logged in, you must ensure that all AlmaLinux OS packages installed on the server are up to date. You can do this by running the following commands:
More about Java
Before we show you the three ways you can install Java 21 on Almalinux, let’s explain the differences between the installations and the terms used, such as JRE, JDK, and JVM.
JVM: Java Virtual Machine – is the engine that runs Java bytecode. As previously mentioned, once you write Java code on one platform, you can run it on any platform that supports Java.
JRE stands for Java Runtime Environment. It’s a package that includes the JVM and the core libraries needed to run Java applications. Using JRE, you can only run Java applications, but you can’t develop them as it does not include the Java compiler, build, or debug tools.
JDK: Java Development Kit is a complete package for Java Developers that includes JRE + development tools.
- Java Oracle JDK: the official Java SE developed by Sun MicroSystems was acquired by Oracle in 2009 and became Oracle Java or Oracle JDK.
- Java OpenJDK: an open-source version of the Oracle JDK maintained by the community.
Step 2. Installing Java 21
Java is omitted by default in AlmaLinux 10, so you can install the OpenJDK Java 21 package using the following commands:
Once completed, you can check the Java version with the command:
If you want to install Java OpenJDK from the Adoptium (Eclipse Temurin) project, you can also check their guide at: https://adoptium.net/installation/linux/
If you want to install Java Oracle JDK, you can use the following commands:
Once installed, you can check the Java version with the command:
Switch Between Different Java Versions
If you have installed multiple versions of Java from different sources, such as OpenJDK and Oracle, you can easily set the default version using the update-alternatives command.
To set the Java default version from Oracle Java 21 to Java OpenJDK 21, run the following command:
You should see a list of all installed Java versions in the following output:
Type 2 and hit Enter to set Java 21 OpenJDK as the default Java version, and then if you run java – version again, you should see the Java version has changed:
Set JAVA_HOME Environment Variable
You must set the JAVA_HOME environment variable to define the Java path in some Java applications.
First, find the Java installation path with the following command:
You should see the path of all Java versions in the following output:
Next, copy your desired Java version path from the above output and paste it in the /etc/environment file:
Add the following line for Java 21:
Next, activate the Java environment variable with the following command:
You can now verify the JAVA_HOME environment variable with the following command:
You should get the following output:
Conclusion
In the above guide, you learned how to install Java 21 on an AlmaLinux 10 server.
Of course, you don’t have to do any of this if you use one of our Linux VPS Hosting services. In that case, you can ask our expert Linux admins to set it up for you. They are available 24/7 and will take care of your request immediately.
If you liked this post, please share it with your friends or leave a comment below.