How to Install Java 8 on Rocky Linux 8 / CentOS 8 / RHEL 8: A Step-by-Step Guide

Java 8 is a popular programming language for both developers and programmers. It is widely used for building complex applications, including desktop, mobile, and web applications. Rocky Linux 8 is a robust and secure operating system for servers and workstations. If you want to install Java 8 on Rocky Linux 8, this blog will guide you through the process step-by-step.

How to Install Java 8 on Rocky Linux 8 / CentOS 8 / RHEL 8: A Step-by-Step Guide

Prerequisites Install Java 8 on Rocky Linux 8

Before we begin, there are some prerequisites that you need to have in order to install Java 8 on Rocky Linux 8. These include

  • A system running Rocky Linux 8.
  • A user account with sudo privileges.
  • A stable internet connection.

Step 1: Update the System

Before installing Java 8 on Rocky Linux 8, it’s important to ensure that your system is up-to-date. Below command will update all the packages on your system up to date.

sudo dnf update

Step 2: Install Java 8 on Rocky Linux 8 

sudo yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel

How to Install Java 8 on Rocky Linux 8

Sample Output:

[sysadminxpert@localhost ~]$ sudo yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel
Last metadata expiration check: 19:59:00 ago on Tue 21 Mar 2023 11:00:58 AM EDT.
Dependencies resolved.
==============================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================
Installing:
java-1.8.0-openjdk x86_64 1:1.8.0.362.b09-2.el8_7 appstream 543 k
java-1.8.0-openjdk-devel x86_64 1:1.8.0.362.b09-2.el8_7 appstream 9.9 M
Installing dependencies:
copy-jdk-configs noarch 4.0-2.el8 appstream 29 k
java-1.8.0-openjdk-headless x86_64 1:1.8.0.362.b09-2.el8_7 appstream 34 M
javapackages-filesystem noarch 5.3.0-2.module+el8.3.0+125+5da1ae29 appstream 29 k
lksctp-tools x86_64 1.0.18-3.el8 baseos 98 k
ttmkfdir x86_64 3.0.9-54.el8 appstream 61 k
tzdata-java noarch 2022g-1.el8 appstream 184 k
xorg-x11-font-utils x86_64 1:7.5-41.el8 appstream 103 k
xorg-x11-fonts-Type1 noarch 7.5-19.el8 appstream 521 k

Transaction Summary
==============================================================================================================================================================
Install 10 Packages

Total download size: 46 M
Installed size: 162 M
Is this ok [y/N]: y
Downloading Packages:
(1/10): copy-jdk-configs-4.0-2.el8.noarch.rpm 5.2 kB/s | 29 kB 00:05
(2/10): java-1.8.0-openjdk-1.8.0.362.b09-2.el8_7.x86_64.rpm 89 kB/s | 543 kB 00:06
(3/10): javapackages-filesystem-5.3.0-2.module+el8.3.0+125+5da1ae29.noarch.rpm 158 kB/s | 29 kB 00:00
(4/10): ttmkfdir-3.0.9-54.el8.x86_64.rpm 245 kB/s | 61 kB 00:00
(5/10): tzdata-java-2022g-1.el8.noarch.rpm 552 kB/s | 184 kB 00:00
(6/10): xorg-x11-font-utils-7.5-41.el8.x86_64.rpm 431 kB/s | 103 kB 00:00
(7/10): xorg-x11-fonts-Type1-7.5-19.el8.noarch.rpm 1.5 MB/s | 521 kB 00:00
(8/10): java-1.8.0-openjdk-devel-1.8.0.362.b09-2.el8_7.x86_64.rpm 888 kB/s | 9.9 MB 00:11
(9/10): lksctp-tools-1.0.18-3.el8.x86_64.rpm 17 kB/s | 98 kB 00:05
(10/10): java-1.8.0-openjdk-headless-1.8.0.362.b09-2.el8_7.x86_64.rpm 2.6 MB/s | 34 MB 00:13
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.4 MB/s | 46 MB 00:31
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Running scriptlet: copy-jdk-configs-4.0-2.el8.noarch 1/1
Running scriptlet: java-1.8.0-openjdk-headless-1:1.8.0.362.b09-2.el8_7.x86_64 1/1
Preparing : 1/1
Installing : lksctp-tools-1.0.18-3.el8.x86_64 1/10
Running scriptlet: lksctp-tools-1.0.18-3.el8.x86_64 1/10
Installing : xorg-x11-font-utils-1:7.5-41.el8.x86_64 2/10
Installing : tzdata-java-2022g-1.el8.noarch 3/10
Installing : ttmkfdir-3.0.9-54.el8.x86_64 4/10
Installing : xorg-x11-fonts-Type1-7.5-19.el8.noarch 5/10
Running scriptlet: xorg-x11-fonts-Type1-7.5-19.el8.noarch 5/10
Installing : javapackages-filesystem-5.3.0-2.module+el8.3.0+125+5da1ae29.noarch 6/10
Installing : copy-jdk-configs-4.0-2.el8.noarch 7/10
Installing : java-1.8.0-openjdk-headless-1:1.8.0.362.b09-2.el8_7.x86_64 8/10
Running scriptlet: java-1.8.0-openjdk-headless-1:1.8.0.362.b09-2.el8_7.x86_64 8/10
Installing : java-1.8.0-openjdk-1:1.8.0.362.b09-2.el8_7.x86_64 9/10
Running scriptlet: java-1.8.0-openjdk-1:1.8.0.362.b09-2.el8_7.x86_64 9/10
Installing : java-1.8.0-openjdk-devel-1:1.8.0.362.b09-2.el8_7.x86_64 10/10
Running scriptlet: java-1.8.0-openjdk-devel-1:1.8.0.362.b09-2.el8_7.x86_64 10/10
Running scriptlet: copy-jdk-configs-4.0-2.el8.noarch 10/10
Running scriptlet: java-1.8.0-openjdk-headless-1:1.8.0.362.b09-2.el8_7.x86_64 10/10
Running scriptlet: java-1.8.0-openjdk-1:1.8.0.362.b09-2.el8_7.x86_64 10/10
Running scriptlet: java-1.8.0-openjdk-devel-1:1.8.0.362.b09-2.el8_7.x86_64 10/10
Verifying : copy-jdk-configs-4.0-2.el8.noarch 1/10
Verifying : java-1.8.0-openjdk-1:1.8.0.362.b09-2.el8_7.x86_64 2/10
Verifying : java-1.8.0-openjdk-devel-1:1.8.0.362.b09-2.el8_7.x86_64 3/10
Verifying : java-1.8.0-openjdk-headless-1:1.8.0.362.b09-2.el8_7.x86_64 4/10
Verifying : javapackages-filesystem-5.3.0-2.module+el8.3.0+125+5da1ae29.noarch 5/10
Verifying : ttmkfdir-3.0.9-54.el8.x86_64 6/10
Verifying : tzdata-java-2022g-1.el8.noarch 7/10
Verifying : xorg-x11-font-utils-1:7.5-41.el8.x86_64 8/10
Verifying : xorg-x11-fonts-Type1-7.5-19.el8.noarch 9/10
Verifying : lksctp-tools-1.0.18-3.el8.x86_64 10/10

Installed:
copy-jdk-configs-4.0-2.el8.noarch java-1.8.0-openjdk-1:1.8.0.362.b09-2.el8_7.x86_64
java-1.8.0-openjdk-devel-1:1.8.0.362.b09-2.el8_7.x86_64 java-1.8.0-openjdk-headless-1:1.8.0.362.b09-2.el8_7.x86_64
javapackages-filesystem-5.3.0-2.module+el8.3.0+125+5da1ae29.noarch lksctp-tools-1.0.18-3.el8.x86_64
ttmkfdir-3.0.9-54.el8.x86_64 tzdata-java-2022g-1.el8.noarch
xorg-x11-font-utils-1:7.5-41.el8.x86_64 xorg-x11-fonts-Type1-7.5-19.el8.noarch

Complete!
[sysadminxpert@localhost ~]$

Step 3: Set Up Java Environment Variables

Once you have installed the Oracle JDK 8 package, you need to set up the Java environment variables on your system. This will allow your system to locate the Java installation when you run Java-based applications.

Step 3.1: Locate where Java is installed (Java path)

From the below command, you will get the exact java path

$ sudo update-alternatives --config java

How to Install Java 8 on Rocky Linux 8

Once you get the above output press the Ctrl+C button so that it will exit. The intention of this command is to get only the path where Java 11 is installed.

Step 3.2: Add Java path at the end of the “~/.bash_profile” file

vim ~/.bash_profile

JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b09-2.el8_7.x86_64/jre/bin/java"

Sample output:

How to Install Java 8 on Rocky Linux 8

Save the file and exit the text editor.

Step 4: Verify Java Installation

To verify that Java 8 has been installed correctly on your system, you can use the following command:

java -version

Sample Output:

[sysadminxpert@localhost ~]$ java -version
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-b09)
OpenJDK 64-Bit Server VM (build 25.362-b09, mixed mode)
[sysadminxpert@localhost ~]$

This command will display the Java version installed on your system.

End of the article, We have shown you how to install Java 8 on Rocky Linux 8.  You just need to follow the steps outlined in this blog, and you should have Java 8 up and running on your system in no time. Once you have installed Java 8, you can start developing and running Java-based applications on your system.

See also:

Java Release information

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs