Installing and using Red Hat build of OpenJDK 21 on RHEL

Red Hat build of OpenJDK 21

Red Hat Customer Content Services

Abstract

Red Hat build of OpenJDK is a Red Hat offering on the Red Hat Enterprise Linux platform. The Installing and using Red Hat build of OpenJDK 21 guide provides an overview of this product and explains how to install the software and start using it.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message.

Chapter 1. Red Hat build of OpenJDK 21 overview

OpenJDK (Open Java Development Kit) is a free and open source implementation of the Java Platform, Standard Edition (Java SE). The Red Hat build of OpenJDK is available in four versions: 8u, 11u, 17u, and 21u.

Packages for the Red Hat build of OpenJDK are made available on Red Hat Enterprise Linux and Microsoft Windows and shipped as a JDK and JRE in the Red Hat Ecosystem Catalog.

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

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-21-openjdk
  2. Check that the installation works:

    $ java -version
    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 21:

    $ 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 21 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.

    For example:

    $ tar -xf archive_file_name.tar.gz -C ~/jres
  5. Create a generic path by using symbolic links to your JRE for easier upgrades:

    $ ln -s ~/jres/archive_file_name ~/jres/java-21
  6. Configure the JAVA_HOME environment variable:

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

    $ printenv | grep JAVA_HOME
    JAVA_HOME=~/jres/java-21
    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
    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-21-openjdk-devel
  2. Check that the installation works:

    $ javac -version
    
    javac 21.0.1

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 21 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 archive_file_name.tar.xz -C ~/jdks
  5. Create a generic path by using symbolic links to your JDK for easier upgrades:

    $ ln -s ~/jdks/archive_file_name ~/jdks/java-21
  6. Configure the JAVA_HOME environment variable:

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

    $ printenv | grep JAVA_HOME
    JAVA_HOME=~/jdks/java-21
    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
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 21

    $ sudo yum install java-21-openjdk

    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*"
  3. Check the current java version:

    $ java -version
    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

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

Note

The different minor versions of Red Hat build of OpenJDK can be found in the /usr/lib/jvm/<minor version> files.

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

Chapter 3. Debug symbols for Red Hat build of OpenJDK 21

Debug symbols help in investigating a crash in Red Hat build of OpenJDK applications.

3.1. Installing the debug symbols

This procedure describes how to install the debug symbols for Red Hat build of OpenJDK.

Prerequisites

  • Installed the gdb package on your local sytem.

    • You can issue the sudo yum install gdb command on your CLI to install this package on your local system.

Procedure

  1. To install the debug symbols, enter the following command:

    $ sudo debuginfo-install java-21-openjdk
    
    $ sudo debuginfo-install java-21-openjdk-headless

    These commands install java-21-openjdk-debuginfo, java-21-openjdk-headless-debuginfo, and additional packages that provide debug symbols for Red Hat build of OpenJDK 21 binaries. These packages are not self-sufficient and do not contain executable binaries.

    Note

    The debuginfo-install is provided by the yum-utils package.

  2. To verify that the debug symbols are installed, enter the following command:

    $ gdb which java
    
    Reading symbols from /usr/bin/java...Reading symbols from /usr/lib/debug/usr/lib/jvm/java-21-version/bin/java-21-version.x86_64.debug...done.
    (gdb)

3.2. Checking the installation location of debug symbols

This procedure explains how to find the location of debug symbols.

Note

If the debuginfo package is installed, but you cannot get the installation location of the package, then check if the correct package and java versions are installed. After confirming the versions, check the location of debug symbols again.

Prerequisites

  • Installed the gdb package on your local sytem.

    • You can issue the sudo yum install gdb command on your CLI to install this package on your local system.
    • Installed the debug symbols package. See Installing the debug symbols.

Procedure

  1. To find the location of debug symbols, use gdb with which java commands:

    $ gdb which java
    
    Reading symbols from /usr/bin/java...Reading symbols from /usr/lib/debug/usr/lib/jvm/java-21-openjdk-version/bin/java-version.x86_64.debug...done.
    (gdb)
  2. Use the following commands to explore the *-debug directory to see all the debug versions of the libraries, which include java, javac, and javah:

    $ cd /usr/lib/debug/lib/jvm/java-21-openjdk-version
    $ tree
    
    OJDK 21 version:
    └── java-21-openjdk-version
    ├── bin
    │   ...
    │ │──  java-java-version.x86_64.debug
    │   ├── javac-java-version.x86_64.debug
    │   ├── javadoc-java-version.x86_64.debug
    │   ...
    └── lib
    ├── jexec-java-version.x86_64.debug
    ├── jli
    │   └── libjli.so-java-version.x86_64.debug
    ├── jspawnhelper-java-version.x86_64.debug
    │   ...
Note

The javac and javah tools are provided by the java-21-openjdk-devel package. You can install the package using the command: $ sudo debuginfo-install java-21-openjdk-devel.

3.3. Checking the configuration of debug symbols

You can check and set configurations for debug symbols.

  • Enter the following command to get a list of the installed packages:

    $ sudo yum list installed | grep 'java-21-openjdk-debuginfo'
  • If some debug information packages have not been installed, enter the following command to install the missing packages:

    $ sudo yum debuginfo-install glibc-2.28-151.el8.x86_64 libgcc-8.4.1-1.el8.x86_64 libstdc++-8.4.1-1.el8.x86_64 sssd-client-2.4.0-9.el8.x86_64 zlib-1.2.11-17.el8.x86_64
  • Run the following command if you want to hit a specific breakpoint:

    $ gdb -ex 'handle SIGSEGV noprint nostop pass' -ex 'set breakpoint pending on' -ex 'break JavaCalls::call' -ex 'run' --args java ./HelloWorld

    The above command completes the following tasks:

    • Handles the SIGSEGV error as the JVM uses SEGV for stack overflow check.
    • Sets pending breakpoints to yes.
    • Calls the break statement in JavaCalls::call function. The function to starts the application in HotSpot (libjvm.so).

3.4. Configuring the debug symbols in a fatal error log file

When a Java application is down due to a JVM crash, a fatal error log file is generated, for example: hs_error, java_error. These error log files are generated in current working directory of the application. The crash file contains information from the stack.

Procedure

  1. You can remove all the debug symbols by using the strip -g command.

    The following code shows an example of non-stripped hs_error file:

    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    V  [libjvm.so+0xb83d2a]  Unsafe_SetLong+0xda
    j  sun.misc.Unsafe.putLong(Ljava/lang/Object;JJ)V+0
    j  Crash.main([Ljava/lang/String;)V+8
    v  ~StubRoutines::call_stub
    V  [libjvm.so+0x6c0e65]  JavaCalls::call_helper(JavaValue*, methodHandle*, JavaCallArguments*, Thread*)+0xc85
    V  [libjvm.so+0x73cc0d]  jni_invoke_static(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, Thread*) [clone .constprop.1]+0x31d
    V  [libjvm.so+0x73fd16]  jni_CallStaticVoidMethod+0x186
    C  [libjli.so+0x48a2]  JavaMain+0x472
    C  [libpthread.so.0+0x9432]  start_thread+0xe2

    The following code shows an example of stripped hs_error file:

    Stack: [0x00007ff7e1a44000,0x00007ff7e1b44000],  sp=0x00007ff7e1b42850,  free space=1018k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    V  [libjvm.so+0xa7ecab]
    j  sun.misc.Unsafe.putAddress(JJ)V+0
    j  Crash.crash()V+5
    j  Crash.main([Ljava/lang/String;)V+0
    v  ~StubRoutines::call_stub
    V  [libjvm.so+0x67133a]
    V  [libjvm.so+0x682bca]
    V  [libjvm.so+0x6968b6]
    C  [libjli.so+0x3989]
    C  [libpthread.so.0+0x7dd5]  start_thread+0xc5
  2. Enter the following command to check that you have the same version of debug symbols and the fatal error log file:

    $ java -version
    Note

    You can also use the sudo update-alternatives --config 'java' to complete this check.

  3. Use the nm command to ensure that libjvm.so has ELF data and text symbols:

    $ nm /usr/lib/debug/usr/lib/jvm/java-21-openjdk-version/lib/server/libjvm.so-version.x86_64.debug

Additional resources

Chapter 4. Updating Red Hat build of OpenJDK 21 on Red Hat Enterprise Linux

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

4.1. Updating Red Hat build of OpenJDK 21 on RHEL by using yum

The installed Red Hat build of OpenJDK packages can be updated using the yum system package manager.

Prerequisites

  • You must have root privileges on the system.

Procedure

  1. Check the current Red Hat build of OpenJDK version:

    $ sudo yum list installed "java*"

    A list of installed Red Hat build of OpenJDK packages displays.

  2. Update a specific package. For example:

    $ sudo yum update java-21-openjdk
  3. Verify that the update worked by checking the current Red Hat build of OpenJDK versions:

    $ java -version
    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'

4.2. Updating Red Hat build of OpenJDK 21 on RHEL by using an archive

You can update Red Hat build of OpenJDK using the archive. This is useful if the Red Hat build of OpenJDK administrator does not have root privileges.

Prerequisites

  • Know the generic path pointing to your JDK or JRE installation. For example, ~/jdks/java-21

Procedure

  1. Remove the existing symbolic link of the generic path to your JDK or JRE.

    For example:

    $ unlink ~/jdks/java-21
  2. Install the latest version of the JDK or JRE in your installation location.

Additional resources

Revised on 2023-11-15 12:50:54 UTC

Legal Notice

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.