How to install Java jdk 11 on RHEL

In this article, we will see how to install Java jdk 11 on RHEL step by step.

How to install Java jdk 11 on RHEL

1. First, verify java jdk is installed or not using the below command.

java --version

How to install Java jdk 11 on RHEL

2. Now update the RHEL using the below command.

sudo yum update

3. Install java jdk 11 on RHEL 11 by running the below command:

sudo yum install java-11-openjdk

If it asks to download, then type y and hit enter.

[administrator@system1 ~]$ sudo yum install java-11-openjdk Updating Subscription Management repositories. Last metadata expiration check: 0:04:11 ago on Thu 12 Jan 2023 12:15:42 PM IST. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: java-11-openjdk x86_64 1:11.0.17.0.8-2.el9_0 rhel-9-for-x86_64-appstream-rpms 249 k Installing dependencies: copy-jdk-configs noarch 4.0-3.el9 rhel-9-for-x86_64-appstream-rpms 29 k java-11-openjdk-headless x86_64 1:11.0.17.0.8-2.el9_0 rhel-9-for-x86_64-appstream-rpms 38 M javapackages-filesystem noarch 6.0.0-3.el9 rhel-9-for-x86_64-appstream-rpms 18 k lksctp-tools x86_64 1.0.19-2.el9 rhel-9-for-x86_64-baseos-rpms 98 k lua x86_64 5.4.2-4.el9_0.3 rhel-9-for-x86_64-appstream-rpms 191 k lua-posix x86_64 35.0-8.el9 rhel-9-for-x86_64-appstream-rpms 155 k mkfontscale x86_64 1.2.1-3.el9 rhel-9-for-x86_64-appstream-rpms 34 k ttmkfdir x86_64 3.0.9-65.el9 rhel-9-for-x86_64-appstream-rpms 55 k tzdata-java noarch 2022g-1.el9_1 rhel-9-for-x86_64-appstream-rpms 234 k xorg-x11-fonts-Type1 noarch 7.5-33.el9 rhel-9-for-x86_64-appstream-rpms 509 k Transaction Summary ================================================================================ Install 11 Packages Total download size: 40 M Installed size: 175 M Is this ok [y/N]: y Downloading Packages: (1/11): lua-posix-35.0-8.el9.x86_64.rpm 312 kB/s | 155 kB 00:00 (2/11): copy-jdk-configs-4.0-3.el9.noarch.rpm 57 kB/s | 29 kB 00:00 (3/11): mkfontscale-1.2.1-3.el9.x86_64.rpm 74 kB/s | 34 kB 00:00 (4/11): lksctp-tools-1.0.19-2.el9.x86_64.rpm 80 kB/s | 98 kB 00:01 (5/11): javapackages-filesystem-6.0.0-3.el9.noa 57 kB/s | 18 kB 00:00 (6/11): java-11-openjdk-11.0.17.0.8-2.el9_0.x86 642 kB/s | 249 kB 00:00 (7/11): ttmkfdir-3.0.9-65.el9.x86_64.rpm 32 kB/s | 55 kB 00:01 (8/11): lua-5.4.2-4.el9_0.3.x86_64.rpm 293 kB/s | 191 kB 00:00 (9/11): tzdata-java-2022g-1.el9_1.noarch.rpm 499 kB/s | 234 kB 00:00 (10/11): xorg-x11-fonts-Type1-7.5-33.el9.noarch 188 kB/s | 509 kB 00:02 (11/11): java-11-openjdk-headless-11.0.17.0.8-2 3.3 MB/s | 38 MB 00:11 -------------------------------------------------------------------------------- Total 3.0 MB/s | 40 MB 00:12 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Running scriptlet: copy-jdk-configs-4.0-3.el9.noarch 1/1 Running scriptlet: java-11-openjdk-headless-1:11.0.17.0.8-2.el9_0.x86_6 1/1 Preparing : 1/1 Installing : tzdata-java-2022g-1.el9_1.noarch 1/11 Installing : lua-5.4.2-4.el9_0.3.x86_64 2/11 Installing : javapackages-filesystem-6.0.0-3.el9.noarch 3/11 Installing : ttmkfdir-3.0.9-65.el9.x86_64 4/11 Installing : mkfontscale-1.2.1-3.el9.x86_64 5/11 Installing : xorg-x11-fonts-Type1-7.5-33.el9.noarch 6/11 Running scriptlet: xorg-x11-fonts-Type1-7.5-33.el9.noarch 6/11 Installing : lua-posix-35.0-8.el9.x86_64 7/11 Installing : copy-jdk-configs-4.0-3.el9.noarch 8/11 Installing : lksctp-tools-1.0.19-2.el9.x86_64 9/11 Installing : java-11-openjdk-headless-1:11.0.17.0.8-2.el9_0.x86 10/11 Running scriptlet: java-11-openjdk-headless-1:11.0.17.0.8-2.el9_0.x86 10/11 Installing : java-11-openjdk-1:11.0.17.0.8-2.el9_0.x86_64 11/11 Running scriptlet: java-11-openjdk-1:11.0.17.0.8-2.el9_0.x86_64 11/11 Running scriptlet: copy-jdk-configs-4.0-3.el9.noarch 11/11 Running scriptlet: java-11-openjdk-headless-1:11.0.17.0.8-2.el9_0.x86 11/11 Running scriptlet: java-11-openjdk-1:11.0.17.0.8-2.el9_0.x86_64 11/11 Verifying : lksctp-tools-1.0.19-2.el9.x86_64 1/11 Verifying : copy-jdk-configs-4.0-3.el9.noarch 2/11 Verifying : lua-posix-35.0-8.el9.x86_64 3/11 Verifying : mkfontscale-1.2.1-3.el9.x86_64 4/11 Verifying : ttmkfdir-3.0.9-65.el9.x86_64 5/11 Verifying : javapackages-filesystem-6.0.0-3.el9.noarch 6/11 Verifying : java-11-openjdk-1:11.0.17.0.8-2.el9_0.x86_64 7/11 Verifying : xorg-x11-fonts-Type1-7.5-33.el9.noarch 8/11 Verifying : java-11-openjdk-headless-1:11.0.17.0.8-2.el9_0.x86 9/11 Verifying : lua-5.4.2-4.el9_0.3.x86_64 10/11 Verifying : tzdata-java-2022g-1.el9_1.noarch 11/11 Installed products updated. Installed: copy-jdk-configs-4.0-3.el9.noarch java-11-openjdk-1:11.0.17.0.8-2.el9_0.x86_64 java-11-openjdk-headless-1:11.0.17.0.8-2.el9_0.x86_64 javapackages-filesystem-6.0.0-3.el9.noarch lksctp-tools-1.0.19-2.el9.x86_64 lua-5.4.2-4.el9_0.3.x86_64 lua-posix-35.0-8.el9.x86_64 mkfontscale-1.2.1-3.el9.x86_64 ttmkfdir-3.0.9-65.el9.x86_64 tzdata-java-2022g-1.el9_1.noarch xorg-x11-fonts-Type1-7.5-33.el9.noarch Complete!

4. Now verify again, java installed or not by running below command.

java --version

5. Now, install the Java Development Kit with the following command:

sudo yum install java-11-openjdk-devel

How to set JAVA_HOME environment variable:

1. First, locate where Java is installed:

sudo update-alternatives --config java

2. Once you see all the paths, copy the one of your preferred Java version.

3. Then, open the .bash_profile with any text editor. In this example, we use vim:

vim .bash_profile

4. At the bottom of the file, add a line which specifies the location of JAVA_HOME in the following manner:

JAVA_HOME=”/your/installation/path/”