Installing OpenJDK on RHEL-based Systems

Steps for installing OpenJDK Java on RHEL-based Systems.

Configure your operating system to use the latest version of OpenJDK 8.

Note: After installing the JDK, you may need to set JAVA_HOME to your profile:
  • For shell or bash: export JAVA_HOME=path_to_java_home
  • For csh (C shell): setenv JAVA_HOME=path_to_java_home

Procedure

  1. Check which version of the JDK your system is using:
    java -version
    If Oracle Java is used, the results should look like:
    java version "1.8.0_221"
    Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
    If the OpenJDK is used, the results should look like:
    openjdk version "1.8.0_181"
    OpenJDK Runtime Environment (build 1.8.0_181-b13)
    OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
  2. Install OpenJDK
    sudo yum install java-1.8.0-openjdk

    The latest JDK is installed.

  3. Check the version of the JDK:
    java -version
    openjdk version "1.8.0_232"
    OpenJDK Runtime Environment (build 1.8.0_232-b09)
    OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
    
  4. If the Oracle Java is still being used, use the alternatives command to switch it. For example:
    sudo alternatives --config java
    There are 2 programs which provide java.
    
      Selection      Command
    ------------------------------------------------------------
       1             /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
    *+ 2             /usr/java/jdk1.8.0_181/bin/java
    
    Enter to keep the current selection [+ ], or type selection number: