Red Hat Enterprise Linux-8-Installing Updating and Configuring Java On RHEL 8-En-US
Red Hat Enterprise Linux-8-Installing Updating and Configuring Java On RHEL 8-En-US
Red Hat Enterprise Linux-8-Installing Updating and Configuring Java On RHEL 8-En-US
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.
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.
Abstract
This document describes the different features and utilities that make Red Hat Enterprise Linux 8
an ideal enterprise platform for Java application development.
Table of Contents
Table of Contents
. . . . . . . . . . . . . FEEDBACK
PROVIDING . . . . . . . . . . . . ON
. . . .RED
. . . . .HAT
. . . . .DOCUMENTATION
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . .
. . . . . . . . . . . 1.. .RED
CHAPTER . . . . .HAT
. . . . .OPENJDK
. . . . . . . . . . .OVERVIEW
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . .
.CHAPTER
. . . . . . . . . . 2.
. . INSTALLING
. . . . . . . . . . . . . .JAVA
. . . . . . ON
. . . .RHEL
. . . . . . 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5. . . . . . . . . . . . .
2.1. INSTALLING A JRE ON RHEL USING YUM 5
Procedure 5
2.2. INSTALLING A JRE ON RHEL USING AN ARCHIVE PORTABLE BUNDLE 5
Procedure 6
2.3. INSTALLING A JDK ON RHEL 8 USING YUM 6
Procedure 7
2.4. INSTALLING A JDK ON RHEL 8 USING AN ARCHIVE PORTABLE BUNDLE 7
Procedure 7
2.5. INSTALLING MULTIPLE MAJOR VERSIONS OF OPENJDK ON RHEL USING YUM 8
Prerequisites 8
Procedure 8
2.6. INSTALLING MULTIPLE MAJOR VERSIONS OF OPENJDK ON RHEL USING AN ARCHIVE PORTABLE
BUNDLE 8
2.7. INSTALLING MULTIPLE MINOR VERSIONS OF OPENJDK ON RHEL USING YUM 9
Procedure 9
2.8. INSTALLING MULTIPLE MINOR VERSIONS OF OPENJDK ON RHEL USING AN ARCHIVE PORTABLE
BUNDLE 9
.CHAPTER
. . . . . . . . . . 3.
. . UPDATING
. . . . . . . . . . . . JAVA
. . . . . . .ON
. . . RHEL
. . . . . . .8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
..............
3.1. UPDATING JAVA ON RHEL 8 USING YUM 10
Procedure 10
3.2. UPDATING JAVA ON RHEL 8 USING AN ARCHIVE 10
Prerequisites 10
Procedure 10
. . . . . . . . . . . 4.
CHAPTER . . .CONFIGURING
. . . . . . . . . . . . . . . .JAVA
. . . . . .ON
. . . .RHEL
. . . . . .8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11. . . . . . . . . . . . .
4.1. INTERACTIVELY SELECTING A SYSTEM-WIDE JAVA VERSION ON RHEL 11
Prerequisites 11
Procedure 11
4.2. NON-INTERACTIVELY SELECTING A SYSTEM-WIDE JAVA VERSION ON RHEL 12
Prerequisites 12
Procedure 12
4.3. SELECTING AN INSTALLED JAVA VERSION FOR A SPECIFIC APPLICATION 13
Prerequisites 13
Procedure 13
4.4. SELECTING A SYSTEM-WIDE ZIP-BUNDLE JAVA VERSION 14
Prerequisites 14
Procedure 14
4.5. CONFIGURING THE JAVA_HOME ENVIRONMENT VARIABLE ON RHEL 14
Prerequisites 15
Procedure 15
4.6. CONFIGURING THE HEAP SIZE FOR A JAVA APPLICATION ON RHEL 15
Procedure 15
1
Red Hat Enterprise Linux 8 Installing, updating, and configuring Java on RHEL 8
2
PROVIDING FEEDBACK ON RED HAT DOCUMENTATION
1. Make sure you are viewing the documentation in the Multi-page HTML format. In addition,
ensure you see the Feedback button in the upper right corner of the document.
2. Use your mouse cursor to highlight the part of text that you want to comment on.
3. Click the Add Feedback pop-up that appears below the highlighted text.
3. Fill in the Description field with your suggestion for improvement. Include a link to the
relevant part(s) of documentation.
3
Red Hat Enterprise Linux 8 Installing, updating, and configuring Java on RHEL 8
Multi-platform - OpenJDK is now supported on Windows and RHEL. This helps you standardize
on a single Java platform across desktop, datacenter, and hybrid cloud.
Frequent releases - Red Hat delivers quarterly JRE and JDK updates per year for the
OpenJDK 8 and 11 distributions. These are available as rpm, msi, zip files and as containers.
Long-term support - Red Hat supports the recently released OpenJDK 11, as well as, OpenJDK
7 and 8. For more information about the support lifecycle, see OpenJDK Life Cycle and
Support Policy.
Java Web Start - Red Hat OpenJDK supports Java Web Start for Windows and RHEL.
4
CHAPTER 2. INSTALLING JAVA ON RHEL 8
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.
NOTE
To get short-term supported Java versions, use Extra Packages for Enterprise Linux
(EPEL). For information see EPEL. The name of package is java-latest-openjdk.
Procedure
1. Run the yum command, specifying the package you want to install:
$ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
5
Red Hat Enterprise Linux 8 Installing, updating, and configuring Java on RHEL 8
NOTE
It is recommended that you create a parent directory to contain your JREs and create a
symbolic link to the latest JRE using a generic path. This eases upgrades to later versions.
Procedure
1. Download the latest version of the JRE ZIP bundle for Linux .
$ mkdir ~/jres
$ cd ~/jres
$ tar -xf java-1.8.0-openjdk-1.8.0.242.b08-1.static.jre.openjdkportable.x86_64.tar.xz
3. Create a generic path by using symbolic links to your JRE for easier upgrades:
$ ln -s ~/jres/java-1.8.0-openjdk-1.8.0.242.b08-1.static.jre.openjdkportable.x86_64
~/jres/java-8
$ export JAVA_HOME=~/jres/java-8
NOTE
When installed using this method, Java will only be available for the current user.
6. Add the bin directory of the generic JRE path to the PATH environment variable:
$ export PATH="$JAVA_HOME/bin:$PATH"
7. Verify that java -version works without supplying the full path:
$ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
NOTE
You can ensure that JAVA_HOME environment variable persists for the current user by
exporting the environment variable in ~/.bashrc.
6
CHAPTER 2. INSTALLING JAVA ON RHEL 8
Procedure
1. Run the yum command, specifying the package you want to install:
$ javac -version
javac 1.8.0_242
NOTE
It is recommended that you create a parent directory to contain your JDKs and create a
symbolic link to the latest JDK using a generic path. This eases upgrades to later versions.
Procedure
1. Download the latest version of the JDK ZIP bundle for Linux .
$ mkdir ~/jdks
$ cd ~/jdks
$ tar -xf java-1.8.0-openjdk-1.8.0.242.b08-1.static.jdk.openjdkportable.x86_64.tar.xz
3. Create a generic path by using symbolic links to your JRE for easier upgrades:
$ ln -s ~/jdks/java-1.8.0-openjdk-1.8.0.242.b08-1.static.jdk.openjdkportable.x86_64
~/jdks/java-8
$ export JAVA_HOME=~/jdks/java-8
NOTE
When installed using this method, Java will only be available for the current user.
7
Red Hat Enterprise Linux 8 Installing, updating, and configuring Java on RHEL 8
6. Add the bin directory of the generic JDK path to the PATH environment variable:
$ export PATH="$JAVA_HOME/bin:$PATH"
7. Verify that javac -version works without supplying the full path:
$ javac -version
javac "1.8.0_242"
NOTE
You can ensure that JAVA_HOME environment variable persists for the current user by
exporting the environment variable in ~/.bashrc.
Prerequisites
A Red Hat Subscription Manager (RHSM) account with an active subscription that provides
access to a repository that provides the OpenJDK versions you want to install.
Procedure
1. Run the yum command, specifying the package you want to install:
$ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
You can configure the default Java version to use by using java --alternatives. For more information
see Selecting a system-wide java version .
NOTE
8
CHAPTER 2. INSTALLING JAVA ON RHEL 8
NOTE
For instructions how to configure the default Java version for the system, see Selecting a
system-wide zip-bundle java version.
Procedure
Add the installonlypkgs option in /etc/yum.conf to specify the Java 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:
The different minor versions of OpenJDK can be found in the /usr/lib/jvm/<minor version>
files.
For example, the following shows part of /usr/lib/jvm/java-1.8.0-openjdk-1.8.0:
$ /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el8_1.x86_64/bin/java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
$ /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-7.b11.el7.x86_64/bin/java -version
openjdk version "1.8.0_172"
OpenJDK Runtime Environment (build 1.8.0_172-b11)
OpenJDK 64-Bit Server VM (build 25.172-b11, mixed mode)
You can choose system-wide using version by following Selecting a system-wide java version .
NOTE
For instructions how to choose a default minor version for the system, see Selecting a
system-wide zip-bundle java version.
9
Red Hat Enterprise Linux 8 Installing, updating, and configuring Java on RHEL 8
Procedure
Installed Packages
java-1.8.0-openjdk.x86_64 1:1.8.0.131.b08-0.fc31 @updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.131.b08-0.fc31 @updates
3. Verify that the update worked by checking the current Java versions:
# java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
Prerequisites
Know the generic path pointing to your Java Development Kit (JDK) or Java Runtime
Environment (JRE) installation. For example, ~/jdks/java-11
Procedure
1. Remove the existing symbolic link of the generic path to your JDK or JRE.
For example:
$ unlink ~/jdks/java-11
2. Install the latest version of the JDK or JRE in your installation location.
10
CHAPTER 4. CONFIGURING JAVA ON RHEL 8
NOTE
If you do not have root privileges, you can select a Java version by configuring the
JAVA_HOME environment variable.
Prerequisites
Multiple versions of Java were installed using the yum package manager.
Procedure
Installed Packages
java-1.8.0-openjdk.x86_64 1:1.8.0.242.b08-0.el8_1 @rhel-8-
appstream-rpms
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.242.b08-0.el8_1 @rhel-8-
appstream-rpms
java-11-openjdk.x86_64 1:11.0.6.10-0.el8_1 @rhel-8-
appstream-rpms
java-11-openjdk-headless.x86_64 1:11.0.6.10-0.el8_1 @rhel-8-
appstream-rpms
javapackages-filesystem.noarch 5.3.0-1.module+el8+2447+6f56d9a6 @rhel-
8-appstream-rpms
2. Display the Java versions that can be used for a specific Java command and select the one to
use:
Selection Command
-----------------------------------------------
*+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-
0.el8_1.x86_64/jre/bin/java)
2 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.6.10-
0.el8_1.x86_64/bin/java)
11
Red Hat Enterprise Linux 8 Installing, updating, and configuring Java on RHEL 8
The current Java version for the specified Java command is marked with a plus sign.
3. Press Enter to keep the current selection or enter the Selection number of the Java version
you want to select followed by the Enter key.
The default Java version for the system is the selected version.
$ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
NOTE
This procedure configures the java command. Then javac command can be set
up in a similar way, but it operates independently.
If you have a JDK installed, alternatives provides more possible selections. In particular, the
javac master alternative switches many binaries provided by the -devel sub-package. Even if
you have JDK installed, java (and other JRE masters) and javac (and other JDK masters) still
operate separately, so you can have different selections for JRE and JDK.
The alternatives --config java command affects the jre and its associated slaves. If you want to
change the JDK, use the javac alternatives command. The --config javac utility configures
the SDK and related slaves. To see all possible masters, use alternatives --list and check all of
the java,javac, jre, and sdk masters.
NOTE
If you do not have root privileges, you can select a Java version by configuring the
JAVA_HOME environment variable.
Prerequisites
Multiple versions of Java were installed using the yum package manager.
Procedure
1. Select the major Java version to switch to. For example, for Java 11, use java-11-openjdk.
12
CHAPTER 4. CONFIGURING JAVA ON RHEL 8
1. Select the major Java version to switch to. For example, for Java 11, use java-11-openjdk.
# PKG_NAME=java-11-openjdk`
# JAVA_TO_SELECT=$(alternatives --display java | grep "family $PKG_NAME" | cut -d' ' -
f1)`
# alternatives --set java $JAVA_TO_SELECT`
2. Verify that the active Java version is the one you specified.
$ java -version
openjdk version "11.0.3" 2019-04-16 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.3+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.3+7-LTS, mixed mode, sharing)
NOTE
NOTE
Prerequisites
Procedure
1. Set the JAVA_HOME environment variable. For example, if openjdk-11 was installed using yum:
$ JAVA_HOME=/usr/lib/jvm/java-11-openjdk
NOTE
$ mvn --version
Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 1.8.0_242, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-
13
Red Hat Enterprise Linux 8 Installing, updating, and configuring Java on RHEL 8
openjdk-1.8.0.242.b08-0.el8_1.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-147.3.1.el8_1.x86_64", arch: "amd64", family: "unix"
Prerequisites
Know the locations of the Java versions installed using ZIP bundles.
Procedure
To specify the Java version to use for a single session:
1. Configure JAVA_HOME with the path to the Java version you want used system-wide.
$ export JAVA_HOME=/opt/jdk/jdk-11.0.3
To specify the Java version to use permanently for a single user, add these commands into ~/.bashrc:
export JAVA_HOME=/opt/jdk/jdk-11.0.3
export PATH="$JAVA_HOME/bin:$PATH"
To specify the Java version to use permanently for all users, add these commands into /etc/bashrc:
export JAVA_HOME=/opt/jdk/jdk-11.0.3
export PATH="$JAVA_HOME/bin:$PATH"
NOTE
14
CHAPTER 4. CONFIGURING JAVA ON RHEL 8
Some applications require you to set the JAVA_HOME environment variable so that they can find the
Java installation.
Prerequisites
Procedure
NOTE
NOTE
Procedure
Add the maximum heap size option to the Java command when running your application
For example to set the maximum heap size to 100 megabytes use the -Xmx100m option.
For OpenJDK 8:
For more information about the Xmx option, see -Xmxsize in Java documentation.
15