Chapter 4. Selecting a system-wide archive Red Hat build of OpenJDK version

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:

  1. Configure JAVA_HOME with 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.35

  2. Add $JAVA_HOME/bin to the PATH environment 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"

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"
Note

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