In this tutorial, we will show you how to install Java on AlmaLinux 8. For those of you who didn’t know, Java is a general-purpose and object-oriented programming language, that lets application developers write once and run everywhere. This means that a compiled java code runs on all platforms that support Java without the need for recompilation. JDK is a collection of various programming tools such as JRE (Java Runtime Environment), Java, Javac, Jar, and many others.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of Java on AlmaLinux 8. You can follow the same instructions for Rocky Linux.
- A server running one of the following operating systems: AlmaLinux 8.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install Java on AlmaLinux 8
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf update sudo dnf install epel-release
Step 2. Installing Java on AlmaLinux 8.
Here we will install the OpenJDK version that is available in the official repo. You can go for an older version as well if you want. Choose and install the one as per your choice:
- Install Java 11
sudo dnf install java-11-openjdk
- Install Java 8
sudo dnf install java-1.8.0-openjdk
Once the Java installation is complete, run the below command to verify the Java version:
openjdk version "11.0.11" 2021-07-21 LTS OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode, sharing)
Step 3. Set Default Java Version on AlmaLinux.
With multiple Java versions installed on your system, you can set the default one with the following steps:
sudo alternatives --config java
[root@idroot ~]# alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-18.104.22.168.b09-2.el8_1.x86_64/jre/bin/java) *+ 2 /usr/java/jdk-11.0.11/bin/java Enter to keep the current selection[+], or type selection number: 1
Now verify the set version using the following command below:
java version "11.0.11" 2021-07-21 Java(TM) SE Runtime Environment (build 16.0.2+7-67) Java HotSpot(TM) 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)
Congratulations! You have successfully installed Java. Thanks for using this tutorial for installing Java on your AlmaLinux 8 system. For additional help or useful information, we recommend you check the official Java website.