Can multiple major versions of java be installed on Red Hat Enterprise Linux?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux

Issue

  • Can I install multiple java major versions on Red Hat Enterprise Linux systems?
  • I want to install java-1.8.0-openjdk.x86_64 and java-11-openjdk.x86_64 packages on RHEL, is it possible?
  • If I install multiple versions of java i.e. java-1.8.0-openjdk.x86_64 and java-11-openjdk.x86_64 on RHEL, which would be taken as default?

Resolution

  • Yes. Installing multiple java major version packages is possible.

    • Below is an example from the system after installing 1.8.0, 11 and 17 versions of OpenJDK(java-1.8.0-openjdk.x86_64, java-11-openjdk.x86_64 and java-17-openjdk.x86_64)
    # alternatives --config java
     
    There are 3 programs which provide 'java'.
    
    Selection    Command
    -----------------------------------------------
    1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-9.el9.x86_64/jre/bin/java)
    2           java-17-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.2.0.8-5.el9.x86_64/bin/java)
    *+ 3           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.14.1.1-6.el9.x86_64/bin/java)
    
    Enter to keep the current selection[+], or type selection number:
    
  • The default system java (+) would be set to the java package having the highest priority value.

    # java -version
    openjdk version "11.0.14.1" 2022-02-08 LTS
    OpenJDK Runtime Environment 18.9 (build 11.0.14.1+1-LTS)
    OpenJDK 64-Bit Server VM 18.9 (build 11.0.14.1+1-LTS, mixed mode, sharing)
    
    # alternatives --display java | grep -i priority
    /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-9.el9.x86_64/jre/bin/java - family java-1.8.0-openjdk.x86_64 priority 1
    /usr/lib/jvm/java-17-openjdk-17.0.2.0.8-5.el9.x86_64/bin/java - family java-17-openjdk.x86_64 priority 1
    /usr/lib/jvm/java-11-openjdk-11.0.14.1.1-6.el9.x86_64/bin/java - family java-11-openjdk.x86_64 priority 11001421
    
  • It can be configured to another version by providing the selection in the above alternatives --config java command.

Diagnostic Steps

If you wish to install multiple copies of the same minor version of Java, refer to:

Category
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.