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 install java-17-openjdk-devel On many systems, you can install the default Java set by the distribution: install java yum
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): Switch Default Version Select the number corresponding to
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: On Red Hat-based systems
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).
java -version If not installed, you’ll see command not found . List all Java-related packages: