ติดตั้ง Java บน AlmaLinux 8

Step 1. First, let’s start by ensuring your system is up-to-date.

$ sudo dnf update
$ sudo dnf install epel-release

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:

$ java -version
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.15+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.15+9-LTS, mixed mode, sharing)

Step 3. Set Default Java Version on AlmaLinux.

$ sudo alternatives --config java

Step 4: Set the JAVA_HOME environment variable (optional)

$ type java
java is hashed (/usr/bin/java)

Set the variable with the following command:

export JAVA_HOME=/usr