java -version If not installed, you’ll see command not found . List all Java-related packages:
sudo yum remove '*openjdk*' Official Oracle Java RPMs are not in standard repos. Use the Oracle Linux repository or download manually.
sudo yum install oraclelinux-release-el8 sudo yum install java-11-oraclejdk-devel For other distributions, download the RPM from Oracle JDK Downloads and install: install java yum
javac -version Many Java applications require JAVA_HOME . 6.1. Find Java Installation Path dirname $(dirname $(readlink -f $(which java))) Example output: /usr/lib/jvm/java-11-openjdk-11.0.22.0.7-1.el7_9.x86_64 6.2. Set JAVA_HOME Permanently Edit ~/.bashrc or /etc/environment :
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: java -version If not installed, you’ll see command
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:
java -version Sample output:
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 :