Configuring Red Hat build of OpenJDK 17 on RHEL
Abstract
Providing feedback on Red Hat build of OpenJDK documentation Copy linkLink copied to clipboard!
To report an error or to improve our documentation, log in to your Red Hat Jira account and submit an issue. If you do not have a Red Hat Jira account, then you will be prompted to create an account.
Procedure
- Click the following link to create a ticket.
- Enter a brief description of the issue in the Summary.
- Provide a detailed description of the issue or enhancement in the Description. Include a URL to where the issue occurs in the documentation.
- Clicking Create creates and routes the issue to the appropriate documentation team.
Making open source more inclusive Copy linkLink copied to clipboard!
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. Interactively selecting a system-wide Red Hat build of OpenJDK version on RHEL Copy linkLink copied to clipboard!
If you have multiple versions of Red Hat build of OpenJDK installed on RHEL, you can interactively select the default Red Hat build of OpenJDK version to use system-wide.
If you do not have root privileges, you can select a Red Hat build of OpenJDK version by configuring the JAVA_HOME environment variable.
Prerequisites
- You must have root privileges on the system.
-
Multiple versions of Red Hat build of OpenJDK were installed using the
yumpackage manager.
Procedure
View the Red Hat build of OpenJDK versions installed on the system.
$ yum list installed "java*"A list of installed Java packages appears.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display the Red Hat build of OpenJDK versions that can be used for a specific
javacommand and select the one to use:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - The current system-wide Red Hat build of OpenJDK version is marked with an asterisk.
-
The current Red Hat build of OpenJDK version for the specified
javacommand is marked with a plus sign.
Press Enter to keep the current selection or enter the Selection number of the Red Hat build of OpenJDK version you want to select followed by the Enter key.
The default Red Hat build of OpenJDK version for the system is the selected version.
Verify that the chosen binary is selected.
java -version
$ java -version openjdk version "17" 2021-09-14 OpenJDK Runtime Environment 21.9 (build 17+35) OpenJDK 64-Bit Server VM 21.9 (build 17+35, mixed mode, sharing)Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis procedure configures the
javacommand. Thenjavaccommand can be set up in a similar way, but it operates independently.If you have Red Hat build of OpenJDK installed,
alternativesprovides more possible selections. In particular, thejavacmaster alternative switches many binaries provided by the-develsub-package.Even if you have Red Hat build of OpenJDK installed,
java(and other JRE masters) andjavac(and other Red Hat build of OpenJDK masters) still operate separately, so you can have different selections for JRE and JDK. Thealternatives --config javacommand affects thejreand its associated slaves.If you want to change Red Hat build of OpenJDK, use the
javac alternativescommand. The--config javacutility configures theSDKand related slaves. To see all possible masters, usealternatives --listand check all of thejava,javac,jre, andsdkmasters.
Chapter 2. Non-interactively selecting a system-wide Red Hat build of OpenJDK version on RHEL Copy linkLink copied to clipboard!
If you have multiple versions of Red Hat build of OpenJDK installed on RHEL, you can select the default Red Hat build of OpenJDK version to use system-wide in a non-interactive way. This is useful for administrators who have root privileges on a Red Hat Enterprise Linux system and need to switch the default Red Hat build of OpenJDK on many systems in an automated way.
If you do not have root privileges, you can select a Red Hat build of OpenJDK version by configuring the JAVA_HOME environment variable.
Prerequisites
- You must have root privileges on the system.
-
Multiple versions of Red Hat build of OpenJDK were installed using the
yumpackage manager.
Procedure
Select the major Red Hat build of OpenJDK version to switch to. For example, for Red Hat build of OpenJDK 17, use
java-17-openjdk.PKG_NAME=java-17-openjdk JAVA_TO_SELECT=$(alternatives --display java | grep "family $PKG_NAME" | cut -d' ' -f1) alternatives --set java $JAVA_TO_SELECT
# PKG_NAME=java-17-openjdk # JAVA_TO_SELECT=$(alternatives --display java | grep "family $PKG_NAME" | cut -d' ' -f1) # alternatives --set java $JAVA_TO_SELECTCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the active Red Hat build of OpenJDK version is the one you specified.
java -version
$ java -version openjdk version "17" 2021-09-14 OpenJDK Runtime Environment 21.9 (build 17+35) OpenJDK 64-Bit Server VM 21.9 (build 17+35, mixed mode, sharing)Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 3. Selecting an installed Red Hat build of OpenJDK version for a specific application Copy linkLink copied to clipboard!
Some applications require a specific Red Hat build of OpenJDK version to run. If multiple versions of Red Hat build of OpenJDK are installed on the system using the yum package manager or portable bundle, you can select a Red Hat build of OpenJDK version for each application where necessary by setting the value of the JAVA_HOME environment variable or using a wrapper script.
Prerequisites
- Multiple versions of Red Hat build of OpenJDK installed on the machine.
- Ensure that the application you want to run is installed.
Procedure
Set the
JAVA_HOMEenvironment variable. For example, if Red Hat build of OpenJDK 17 was installed usingyum:$ JAVA_HOME=/usr/lib/jvm/java-17-openjdkNoteThe symbolic link
java-17-openjdkis controlled by thealternativescommand.Do one of the following:
Launch the application using the default, system-wide configuration.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Launch the application specifying the
JAVA_HOMEvariable:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 4. Selecting a system-wide archive Red Hat build of OpenJDK version Copy linkLink copied to clipboard!
If you have multiple versions of Red Hat build of OpenJDK installed with the archive on RHEL, you can select a specific Red Hat build of OpenJDK version to use system-wide.
Prerequisites
- Know the locations of the Red Hat build of OpenJDK versions installed using the archive.
Procedure
To specify the Red Hat build of OpenJDK version to use for a single session:
Configure
JAVA_HOMEwith the path to the Red Hat build of OpenJDK version you want used system-wide.$ export JAVA_HOME=/opt/jdk/openjdk-17.0.0.0.35Add
$JAVA_HOME/binto thePATHenvironment variable.$ export PATH="$JAVA_HOME/bin:$PATH"
To specify the Red Hat build of OpenJDK version to use permanently for a single user, add these commands into ~/.bashrc:
export JAVA_HOME=/opt/jdk/openjdk-17.0.0.0.35 export PATH="$JAVA_HOME/bin:$PATH"
export JAVA_HOME=/opt/jdk/openjdk-17.0.0.0.35
export PATH="$JAVA_HOME/bin:$PATH"
To specify the Red Hat build of OpenJDK version to use permanently for all users, add these commands into /etc/bashrc:
export JAVA_HOME=/opt/jdk/openjdk-17.0.0.0.35 export PATH="$JAVA_HOME/bin:$PATH"
export JAVA_HOME=/opt/jdk/openjdk-17.0.0.0.35
export PATH="$JAVA_HOME/bin:$PATH"
If you do not want to redefine JAVA_HOME, add only the PATH command to bashrc, specifying the path to the Java binary. For example, export PATH="/opt/jdk/openjdk-17.0.0.0.35/bin:$PATH".
Additional resources
-
Be aware of the exact meaning of
JAVA_HOME. For more information, see Changes/Decouple system java setting from java command setting.
Chapter 5. Configuring the JAVA_HOME environment variable on RHEL Copy linkLink copied to clipboard!
Some applications require you to set the JAVA_HOME environment variable so that they can find the Red Hat build of OpenJDK installation.
Prerequisites
-
You know where you installed Red Hat build of OpenJDK on your system. For example,
/opt/jdk/11.
Procedure
Set the value of
JAVA_HOME.export JAVA_HOME=/opt/jdk/11
$ export JAVA_HOME=/opt/jdk/11Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that
JAVA_HOMEis set correctly.printenv | grep JAVA_HOME
$ printenv | grep JAVA_HOME JAVA_HOME=/opt/jdk/11Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou can make the value of
JAVA_HOMEpersistent by exporting the environment variable in~/.bashrcfor single users or/etc/bashrcfor system-wide settings. Persistent means that if you close your terminal or reboot your computer, you do not need to reset a value for theJAVA_HOMEenvironment variable.The following example demonstrates using a text editor to enter commands for exporting
JAVA_HOMEin~/.bashrcfor a single user:> vi ~/.bash_profile export JAVA_HOME=/opt/jdk/11 export PATH="$JAVA_HOME/bin:$PATH"
> vi ~/.bash_profile export JAVA_HOME=/opt/jdk/11 export PATH="$JAVA_HOME/bin:$PATH"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
-
Be aware of the exact meaning of
JAVA_HOME. For more information, see Changes/Decouple system java setting from java command setting.
Chapter 6. Configuring the heap size for Red Hat build of OpenJDK application on RHEL Copy linkLink copied to clipboard!
You can configure Red Hat build of OpenJDK to use a customized heap size.
Procedure
Add the maximum heap size option to the
javacommand when running your application. For example, to set the maximum heap size to 100 megabytes, use the-Xmx100moption:java -Xmx100m <your_application_name>
$ java -Xmx100m <your_application_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
-
For more information about the
Xmxoption, see -Xmxsize in the Java documentation.
Revised on 2024-10-29 14:17:48 UTC