Search

Chapter 2. Installing Red Hat build of OpenJDK 17 on Red Hat Enterprise Linux

download PDF

Red Hat build of OpenJDK is an environment for developing and running a wide range of platform-agnostic applications, from mobile applications to desktop and web applications and enterprise systems. Red Hat provides an open source implementation of the Java Platform SE (Standard Edition) called Red Hat build of OpenJDK.

Applications are developed using the JDK (Java Development Kit). Applications are run on a JVM (Java Virtual Machine), which is included in the JRE (Java Runtime Environment) and the JDK. There is also a headless version of Java which has the smallest footprint and does not include the libraries needed for a user interface. The headless version is packaged in the headless subpackage.

Note

If you are unsure whether you need the JRE or the JDK, it is recommended that you install the JDK.

The following sections provide instructions for installing Red Hat build of OpenJDK on Red Hat Enterprise Linux.

Note

You can install multiple major versions of Red Hat build of OpenJDK on your local system. If you need to switch from one major version to another major version, issue the following command in your command-line interface (CLI) and then follow the onscreen prompts:

$ sudo update-alternatives --config 'java'

2.1. Installing a JRE on RHEL using yum

You can install Red Hat build of OpenJDK Java Runtime Environment (JRE) using the system package manager, yum.

Prerequisites

Procedure

  1. Run the yum command, specifying the package you want to install:

    $ sudo yum install java-17-openjdk
  2. Check that the installation works:

    $ java -version
    
    openjdk version "17.0.2" 2022-01-18 LTS
    OpenJDK Runtime Environment 21.9 (build 17.0.2+8-LTS)
    OpenJDK 64-Bit Server VM 21.9 (build 17.0.2+8-LTS, mixed mode, sharing)
    Note

    If the output from the previous command shows that you have a different major version of Red Hat build of OpenJDK checked out on your system, you can enter the following command in your CLI to switch your system to use Red Hat build of OpenJDK 17:

    $ sudo update-alternatives --config 'java'

2.2. Installing a JRE on RHEL using an archive

You can install Red Hat build of OpenJDK Java Runtime Environment (JRE) using an archive. This is useful if the Java administrator does not have root privileges.

Note

To ease the upgrades for later versions create a parent directory to contain your JREs and create a symbolic link to the latest JRE using a generic path.

Procedure

  1. Create a directory to where you want to download the archive file, and then navigate to that directory on your command-line interface (CLI). For example:

    $ mkdir ~/jres
    
    $ cd ~/jres
  2. Navigate to the Software Downloads page on the Red Hat Customer Portal.
  3. Select the latest version of Red Hat build of OpenJDK 17 from the Version drop-down list, and then download the JRE archive for Linux to your local system.
  4. Extract the contents of the archive to a directory of your choice:

    $ tar -xf java-17-openjdk-17.0.2.0.8-3.portable.jre.el7.x86_64.tar.xz -C ~/jres
  5. Create a generic path by using symbolic links to your JRE for easier upgrades:

    $ ln -s ~/jres/java-17-openjdk-17.0.2.0.8-3.portable.jdk.el7.x86_64 ~/jres/java-17
  6. Configure the JAVA_HOME environment variable:

    $ export JAVA_HOME=~/jres/java-17
  7. Verify that JAVA_HOME environment variable is set correctly:

    $ printenv | grep JAVA_HOME
    JAVA_HOME=~/jres/java-17
    Note

    When installed using this method, Java will only be available for the current user.

  8. Add the bin directory of the generic JRE path to the PATH environment variable:

    $ export PATH="$JAVA_HOME/bin:$PATH"
  9. Verify that java -version works without supplying the full path:

    $ java -version
    
    openjdk version "17.0.2" 2022-01-18 LTS
    OpenJDK Runtime Environment 21.9 (build 17.0.2+8-LTS)
    OpenJDK 64-Bit Server VM 21.9 (build 17.0.2+8-LTS, mixed mode, sharing)
    Note

    You can ensure that JAVA_HOME environment variable persists for the current user by exporting the environment variable in ~/.bashrc.

2.3. Installing Red Hat build of OpenJDK on RHEL by using yum

You can install Red Hat build of OpenJDK using the system package manager, yum.

Prerequisites

Procedure

  1. Run the yum command, specifying the package you want to install:

    $ sudo yum install java-17-openjdk-devel
  2. Check that the installation works:

    $ javac -version
    
    javac 17.0.2

2.4. Installing Red Hat build of OpenJDK on RHEL by using an archive

You can install Red Hat build of OpenJDK with an archive. This is useful if the Java administrator does not have root privileges.

Note

To ease upgrades, create a parent directory to contain your JREs and create a symbolic link to the latest JRE using a generic path.

Procedure

  1. Create a directory to where you want to download the archive file, and then navigate to that directory on your command-line interface (CLI). For example:

    $ mkdir ~/jdks
    
    $ cd ~/jdks
  2. Navigate to the Software Downloads page on the Red Hat Customer Portal.
  3. Select the latest version of Red Hat build of OpenJDK 17 from the Version drop-down list, and then download the JDK archive for Linux to your local system.
  4. Extract the contents of the archive to a directory of your choice:

    $ tar -xf java-17-openjdk-17.0.2.0.8-3.portable.jre.el7.x86_64.tar.xz -C ~/jdks
  5. Create a generic path by using symbolic links to your JDK for easier upgrades:

    $ ln -s ~/jdks/java-17-openjdk-17.0.2.0.8-3.portable.jdk.el7.x86_64 ~/jdks/java-17
  6. Configure the JAVA_HOME environment variable:

    $ export JAVA_HOME=~/jdks/java-17
  7. Verify that JAVA_HOME environment variable is set correctly:

    $ printenv | grep JAVA_HOME
    JAVA_HOME=~/jdks/java-17
    Note

    When installed using this method, Java will only be available for the current user.

  8. Add the bin directory of the generic JRE path to the PATH environment variable:

    $ export PATH="$JAVA_HOME/bin:$PATH"
  9. Verify that java -version works without supplying the full path:

    $ java -version
    
    openjdk version "17.0.2" 2022-01-18 LTS
    OpenJDK Runtime Environment 21.9 (build 17.0.2+8-LTS)
    OpenJDK 64-Bit Server VM 21.9 (build 17.0.2+8-LTS, mixed mode, sharing)
Note

You can ensure that JAVA_HOME environment variable persists for the current user by exporting the environment variable in ~/.bashrc.

2.5. Installing multiple major versions of Red Hat build of OpenJDK on RHEL by using yum

You can install multiple versions of Red Hat build of OpenJDK using the system package manager, yum.

Prerequisites

  • A Red Hat Subscription Manager (RHSM) account with an active subscription that provides access to a repository that provides the Red Hat build of OpenJDK you want to install.
  • You must have root privileges on the system.

Procedure

  1. Run the following yum commands to install the package:

    For Red Hat build of OpenJDK 17

    $ sudo yum install java-17-openjdk

    For Red Hat build of OpenJDK 11

    $ sudo yum install java-11-openjdk

    For Red Hat build of OpenJDK 8

    $ sudo yum install java-1.8.0-openjdk
  2. After installing, check the available Java versions:

    $ sudo yum list installed "java*"
    
    Installed Packages
    
    java-1.8.0-openjdk.x86_64    1:1.8.0.322.b06-2.el8_5    @rhel-8-for-x86_64-appstream-rpms
    java-11-openjdk.x86_64    1:11.0.14.0.9-2.el8_5    @rhel-8-for-x86_64-appstream-rpms
    java-17-openjdk.x86_64    1:17.0.2.0.8-4.el8_5    @rhel-8-for-x86_64-appstream-rpms
  3. Check the current java version:

    $ java -version
    
    openjdk version "17.0.2" 2022-01-18 LTS
    OpenJDK Runtime Environment 21.9 (build 17.0.2+8-LTS)
    OpenJDK 64-Bit Server VM 21.9 (build 17.0.2+8-LTS, mixed mode, sharing)
    Note

    You can install multiple major versions of Red Hat build of OpenJDK on your local system. If you need to switch from one major version to another major version, issue the following command in your command-line interface (CLI) and then follow the onscreen prompts:

    $ sudo update-alternatives --config 'java'

Additional resources

2.6. Installing multiple major versions of OpenJDK on RHEL using an archive

You can install multiple major versions of Red Hat build of OpenJDK by using the same procedures found in Installing a JRE on RHEL using an archive or Installing Red Hat build of OpenJDK on RHEL 8 using an archive using multiple major versions.

Note

For instructions how to configure the default Red Hat build of OpenJDK version for the system, see Selecting a system-wide java version.

Additional resources

2.7. Installing multiple minor versions of OpenJDK on RHEL using yum

You can install multiple minor versions of Red Hat build of OpenJDK on RHEL. This is done by preventing the installed minor versions from being updated.

Prerequisites

Procedure

  1. Add the installonlypkgs option in the /etc/yum.conf directory to specify the Red Hat build of OpenJDK packages that yum can install but not update.

    installonlypkgs=java-<version>--openjdk,java-<version>--openjdk-headless,java-<version>--openjdk-devel

    Updates will install new packages while leaving the old versions on the system.

    $ rpm -qa | grep java-17.0.2-openjdk
    
    java-17-openjdk-17.0.1.0.12-2.el8_5.x86_64
    java-17-openjdk-17.0.2.0.8-4.el8_5.x86_64
  2. The different minor versions of Red Hat build of OpenJDK can be found in the /usr/lib/jvm/<minor version> files.

    For example, the following shows part of /usr/lib/jvm/java-17.0.2-openjdk:

    $ /usr/lib/jvm/java-17-openjdk-17.0.2.0.8-4.el8_5.x86_64/bin/java -version
    openjdk version "17.0.2" 2022-01-18 LTS
    OpenJDK Runtime Environment 21.9 (build 17.0.2+8-LTS)
    OpenJDK 64-Bit Server VM 21.9 (build 17.0.2+8-LTS, mixed mode, sharing)
    
    $ /usr/lib/jvm/java-17-openjdk-17.0.1.0.12-2.el8_5.x86_64/bin/java -version
    openjdk version "17" 2021-10-19
    OpenJDK Runtime Environment 21.9 (build 17+35)
    OpenJDK 64-Bit Server VM 21.9 (build 17+35, mixed mode, sharing)

2.8. Installing multiple minor versions of OpenJDK on RHEL using an archive

Installing multiple minor versions is the same as Installing a JRE on RHEL using an archive or Installing Red Hat build of OpenJDK on RHEL 8 using an archive using multiple minor versions.

Note

For instructions how to choose a default minor version for the system, see Non-interactively selecting a system-wide Red Hat build of OpenJDK version on RHEL.

Additional resources

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.