Chapter 2. Installing Red Hat build of OpenJDK 25 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.
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.
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 on-screen prompts:
$ sudo update-alternatives --config 'java'
2.1. Installing a JRE on RHEL by using the DNF package manager Copy linkLink copied to clipboard!
You can install the Red Hat build of OpenJDK Java Runtime Environment (JRE) by using the DNF package manager.
Prerequisites
- Logged in as a user with root privileges on the system.
- Registered your local system to your Red Hat Subscription Manager account. See Using Red Hat Subscription Manager in the Getting Started with RHEL System Registration guide.
Procedure
Run the
dnfcommand, specifying the package you want to install:$ sudo dnf install java-25-openjdkCheck that the installation works:
$ java -versionNoteIf 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 25:
$ sudo update-alternatives --config 'java'
2.2. Installing a JRE on RHEL by using an archive Copy linkLink copied to clipboard!
You can install the Red Hat build of OpenJDK Java Runtime Environment (JRE) by using an archive file. This is useful if the Java administrator does not have root privileges.
To facilitate 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
Create the directory 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- Navigate to the Software Downloads page on the Red Hat Customer Portal.
- Select the latest version of Red Hat build of OpenJDK 25 from the Version drop-down list, and then download the JRE archive for Linux to your local system.
Extract the contents of the archive to a directory of your choice.
For example:
$ tar -xf archive_file_name.tar.gz -C ~/jresCreate a generic path by using symbolic links to your JRE for easier upgrades:
$ ln -s ~/jres/archive_file_name ~/jres/java-25Configure the
JAVA_HOMEenvironment variable:$ export JAVA_HOME=~/jres/java-25Verify that
JAVA_HOMEenvironment variable is set correctly:$ printenv | grep JAVA_HOME JAVA_HOME=~/jres/java-25NoteWhen installed using this method, Java will only be available for the current user.
Add the
bindirectory of the generic JRE path to thePATHenvironment variable:$ export PATH="$JAVA_HOME/bin:$PATH"Verify that
java -versionworks without supplying the full path:$ java -versionNoteYou can ensure that
JAVA_HOMEenvironment 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 the DNF package manager Copy linkLink copied to clipboard!
You can install Red Hat build of OpenJDK by using the DNF package manager.
Prerequisites
- Logged in as a user with root privileges.
- Registered your local system to your Red Hat Subscription Manager account. See Using the Red Hat Subscription Manager in the Getting Started with RHEL System Registration guide.
Procedure
Run the
dnfcommand, specifying the package you want to install:$ sudo dnf install java-25-openjdk-develCheck that the installation works:
$ javac -versionThe preceding command produces output similar to the following:
javac 25.0.1
2.4. Installing Red Hat build of OpenJDK on RHEL by using an archive Copy linkLink copied to clipboard!
You can install Red Hat build of OpenJDK by using an archive file. This is useful if the Java administrator does not have root privileges.
To facilitate upgrades for later versions, create a parent directory to contain your JDKs and create a symbolic link to the latest JDK using a generic path.
Procedure
Create the directory 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- Navigate to the Software Downloads page on the Red Hat Customer Portal.
- Select the latest version of Red Hat build of OpenJDK 25 from the Version drop-down list, and then download the JDK archive for Linux to your local system.
Extract the contents of the archive to a directory of your choice:
$ tar -xf archive_file_name.tar.xz -C ~/jdksCreate a generic path by using symbolic links to your JDK for easier upgrades:
$ ln -s ~/jdks/archive_file_name ~/jdks/java-25Configure the
JAVA_HOMEenvironment variable:$ export JAVA_HOME=~/jdks/java-25Verify that
JAVA_HOMEenvironment variable is set correctly:$ printenv | grep JAVA_HOME JAVA_HOME=~/jdks/java-25NoteWhen installed using this method, Java will only be available for the current user.
Add the
bindirectory of the generic JRE path to thePATHenvironment variable:$ export PATH="$JAVA_HOME/bin:$PATH"Verify that
java -versionworks without supplying the full path:$ java -version
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 the DNF package manager Copy linkLink copied to clipboard!
You can install multiple versions of Red Hat build of OpenJDK by using the DNF package manager.
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
Run the following
dnfcommands to install the package:To install Red Hat build of OpenJDK 25:
$ sudo dnf install java-25-openjdkTo install Red Hat build of OpenJDK 21:
$ sudo dnf install java-21-openjdkTo install Red Hat build of OpenJDK 17:
$ sudo dnf install java-17-openjdkTo install Red Hat build of OpenJDK 11:
$ sudo dnf install java-11-openjdkTo install Red Hat build of OpenJDK 8:
$ sudo dnf install java-1.8.0-openjdkAfter installing, check the available Java versions:
$ sudo yum list installed "java*"Check the current java version:
$ java -versionNoteYou 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
sudo update-alternatives --config 'java'command in your command-line interface (CLI) and then follow the on-screen prompts.You can configure the default Java version to use by using
java --alternatives. For more information, see Non-interactively selecting a system-wide Red Hat build of OpenJDK version on RHEL.
2.6. Installing multiple major versions of Red Hat build of OpenJDK on RHEL by using an archive Copy linkLink copied to clipboard!
You can install multiple major versions of Red Hat build of OpenJDK by using the same procedure that is described in Installing a JRE on RHEL by using an archive or Installing Red Hat build of OpenJDK on RHEL by using an archive.
For instructions on how to configure the default Red Hat build of OpenJDK version for the system, see Non-interactively selecting a system-wide Red Hat build of OpenJDK version on RHEL.
2.7. Installing multiple minor versions of Red Hat build of OpenJDK on RHEL by using the DNF package manager Copy linkLink copied to clipboard!
When using the DNF package manager, you can install multiple minor versions of Red Hat build of OpenJDK on RHEL by preventing the DNF package manager from updating the installed minor versions.
Prerequisites
- Choose system-wide version of Red Hat build of OpenJDK from Non-interactively selecting a system-wide Red Hat build of OpenJDK version on RHEL.
Procedure
Add the
installonlypkgsoption in the/etc/dnf.confdirectory to specify the Red Hat build of OpenJDK packages that the DNF package manager can install but not update.installonlypkgs=java-<version>--openjdk,java-<version>--openjdk-headless,java-<version>--openjdk-develBased on the preceding setting, when you subsequently use the DNF package manager to install a new version of the product, it installs the new packages while leaving the old versions on the system.
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 Red Hat build of OpenJDK on RHEL by using an archive Copy linkLink copied to clipboard!
You can install multiple minor versions of Red Hat build of OpenJDK by using the same procedure that is described in Installing a JRE on RHEL by using an archive or Installing Red Hat build of OpenJDK on RHEL by using an archive.
For instructions on how to to choose a default minor version for the system, see Non-interactively selecting a system-wide Red Hat build of OpenJDK version on RHEL.