Installing Oracle JDK on RHEL-based Systems 

You must configure your operating system to use the Oracle JDK 7 or 8, or OpenJDK 7.

Configure your operating system to use the latest version of Oracle Java SE Runtime Environment 8 or OpenJDK 7.

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_65"
    Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
    Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
  2. If necessary, go to Oracle Java SE Downloads, accept the license agreement, and download the installer for your distribution.
    Note: If installing the Oracle JDK in a cloud environment, accept the license agreement, download the installer to your local client, and then use scp (secure copy) to transfer the file to your cloud machines.
  3. From the directory where you downloaded the package, run the install:
    $ sudo rpm -ivh jdk-8uversion-linux-x64.rpm

    The RPM installs the JDK into the /usr/java/ directory.

  4. Use the alternatives command to add a symbolic link to the Oracle JDK installation so that your system uses the Oracle JDK instead of the OpenJDK JDK:
    $ sudo alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_version/bin/java 200000
    If you have any problems, set the PATH and JAVA_HOME variables:
    export PATH="$PATH:/usr/java/latest/bin"
    set JAVA_HOME=/usr/java/latest
  5. Make sure your system is now using the correct JDK. For example:
    $ java -version
    java version "1.8.0_65"
    Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
    Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
  6. If the OpenJDK JDK 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.7.0-openjdk.x86_64/bin/java
    *+ 2             /usr/java/jdk1.8.0_65/bin/java
    
    Enter to keep the current selection [+ ], or type selection number: