How to install multiple minor versions of OpenJDK on a Red Hat Enterprise Linux system?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux (RHEL)
    • 7
    • 8
    • 9
  • OpenJDK
    • 1.6
    • 1.7
    • 1.8
    • 11
    • 17

Issue

  • Is it possible to install multiple minor versions of OpenJDK using the rpm packaging system?

Resolution

Installing multiple minor versions of OpenJDK using the rpm packaging system can be achieved by using the installonlypkgs option in /etc/yum.conf. installonlypkgs takes a space or comma delimited list of packages which yum can install, but will never update.
More detail on installonlypkgs can be found in the RHEL 7 System administrators guide.

  • Add the following entry in /etc/yum.conf:

    installonlypkgs=java-1.8.0-openjdk,java-1.8.0-openjdk-headless,java-1.8.0-openjdk-devel
    
  • For java-11 add this instead of the line above:

    installonlypkgs=java-11-openjdk,java-11-openjdk-headless,java-11-openjdk-devel
    
  • New versions will get added with updates, and the old versions will remain on the system.

  • Please observe that only the new package gets installed, and the old ones remain on the system:

    #rpm -qa | grep java-1.8.0-openjdk
    java-1.8.0-openjdk-1.8.0.172-7.b11.el7.x86_64
    java-1.8.0-openjdk-headless-1.8.0.171-9.b12.el7.x86_64
    java-1.8.0-openjdk-devel-1.8.0.171-9.b12.el7.x86_64
    java-1.8.0-openjdk-headless-1.8.0.172-7.b11.el7.x86_64
    java-1.8.0-openjdk-1.8.0.171-9.b12.el7.x86_64
    java-1.8.0-openjdk-devel-1.8.0.172-7.b11.el7.x86_64
    
  • The different versions of OpenJDK can be found in the /usr/lib/jvm/{version of OpenJDK}

    #/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-9.b12.el7.x86_64/bin/java -version
    openjdk version "1.8.0_171"
    OpenJDK Runtime Environment (build 1.8.0_171-b12)
    OpenJDK 64-Bit Server VM (build 25.171-b12, mixed mode)
        
    #/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-7.b11.el7.x86_64/bin/java -version
    openjdk version "1.8.0_172"
    OpenJDK Runtime Environment (build 1.8.0_172-b11)
    OpenJDK 64-Bit Server VM (build 25.172-b11, mixed mode)
    
  • Old versions can be installed by specifying an explicit version number. Example:

    #yum install java-1.8.0-openjdk-1.8.0.212.b04
    

Please refer to the following solution to set a specific version as default if needed:
Can multiple major versions of java be installed on Red Hat Enterprise Linux?

Note that in RHEL10 the ability to install multiple minor versions of java installed by rpm has been removed. If this is a requirement, it will be necessary to install a portable build.

Root Cause

The default behavior of yum is to update existing packages on a system.

SBR
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.