Java Yum | Install
sudo yum update -y : On RHEL 8+ and derivatives, yum is symlinked to dnf . Both commands work interchangeably. 3.2. Check Existing Java Installations Verify if Java is already present:
openjdk version "11.0.22" 2024-01-16 LTS OpenJDK Runtime Environment (Red Hat build 11.0.22+7-LTS) OpenJDK 64-Bit Server VM (Red Hat build 11.0.22+7-LTS, mixed mode, sharing) Check compiler (if JDK installed):
sudo yum install java-latest-openjdk Or for the latest JDK: install java yum
java -version If not installed, you’ll see command not found . List all Java-related packages:
echo "export JAVA_HOME=/usr/lib/jvm/$(ls /usr/lib/jvm | grep -m 1 'java-11-openjdk')" >> ~/.bashrc echo "export PATH=\$JAVA_HOME/bin:\$PATH" >> ~/.bashrc source ~/.bashrc Verify: sudo yum update -y : On RHEL 8+
sudo yum install java-latest-openjdk-devel If multiple Java versions are installed, use alternatives to set the default. 4.1. List Configured Java Versions sudo alternatives --config java 4.2. Switch Default Version Select the number corresponding to the desired version. 4.3. Set javac (Compiler) Similarly sudo alternatives --config javac 5. Verify Installation Check Java runtime:
Here’s a step-by-step write-up on installing Java using yum on a RHEL-based Linux distribution (such as CentOS, Rocky Linux, AlmaLinux, or Amazon Linux). 1. Overview Java is a essential runtime and development environment for many applications. On Red Hat-based systems, yum (or dnf on newer versions) provides an easy way to install various Java versions, including OpenJDK (the open-source reference implementation) and, optionally, Oracle Java (via third-party repos). Check Existing Java Installations Verify if Java is
sudo yum list available | grep -i java Option A: Install Headless JRE (Minimal runtime, no GUI) sudo yum install java-11-openjdk-headless Option B: Install Full JRE (Includes sound, graphics support) sudo yum install java-11-openjdk Option C: Install JDK (For development) sudo yum install java-11-openjdk-devel Option D: Install a Different Java Version Replace 11 with another version, e.g., 8 , 17 , 21 :