Install Java 8 on CentOS 8 / RHEL 8 / Rocky Linux 8

Posted on 129 views

How can I install Java 8 on CentOS 8 / RHEL 8 / Rocky Linux 8?. On Red Hat Enterprise Linux (RHEL) 8, two major versions of Java are available – Java 11 and Java 8. Our last article addressed the installation of Java 11 on CentOS / RHEL 8. In this article, I’ll cover the installation of Java 8, specifically, JDK (Java Development Kit) 8 on CentOS 8 / RHEL 8 / Rocky Linux 8.

You can check features of RHEL 8 and optionally how to install RHEL 8 if you’re a new user.

Install Java 8 on CentOS 8 / RHEL 8 / Rocky Linux 8 Linux

To install JDK 8 on your CentOS 8 / RHEL 8 / Rocky Linux 8 server or workstation machine, Use the following command.

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

Check version to validate installation of Java 8 on CentOS 8 / RHEL 8.

$ java -version
openjdk version "1.8.0_322"
OpenJDK Runtime Environment (build 1.8.0_322-b06)
OpenJDK 64-Bit Server VM (build 25.322-b06, mixed mode)

Set Java environment variables.

cat <

Activate Java environment.

source /etc/profile.d/java8.sh

Test the variables:

$ echo $JAVA_HOME
/usr/lib/jvm/jre-openjdk

$ echo $PATH
/home/rocky/.local/bin:/home/rocky/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/lib/jvm/jre-openjdk/bin

$ echo $CLASSPATH
.:/usr/lib/jvm/jre-openjdk/jre/lib:/usr/lib/jvm/jre-openjdk/lib:/usr/lib/jvm/jre-openjdk/lib/tools.jar

Create a simple Java application to see Java 8 working on CentOS 8 / RHEL 8 / Rocky Linux 8.

cat > HelloWorld.java <

Compile your Java source code.

$ javac HelloWorld.java

This will create HelloWorld.class file, which is the bytecode embodiment of the source code. To run the HelloWorld.class file, use:

$ java HelloWorld
Hello World

You now have Java installed and configured on CentOS 8 / RHEL 8 / Rocky Linux 8. Enjoy your development.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.