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 <<EOF | sudo tee /etc/profile.d/java8.sh
export JAVA_HOME=/usr/lib/jvm/jre-openjdk
export PATH=\$PATH:\$JAVA_HOME/bin
export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar
EOF

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 <<EOF
public class HelloWorld {
	public static void main(String args[]) {
		System.out.println("Hello World");
	}
}
EOF

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!!.

Video Courses to Learn Java Programming Language:

Want to Master Java Programming language, check:

For Java 11, use how to install Java 11 on RHEL / CentOS 8.

YOU CAN SUPPORT OUR WORK WITH A CUP OF COFFEE


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

PayPal Support
Previous articleInstall Google Chrome Browser on CentOS 8 | RHEL 8
Next articleHow To Install MySQL 5.7 on Fedora 34/33/32/31/30
Founder of Computingforgeeks. Expertise in Virtualization, Cloud, Linux/UNIX Administration, Automation,Storage Systems, Containers, Server Clustering e.t.c.

LEAVE A REPLY

Please enter your comment!
Please enter your name here