How to Install Java 8 on CentOS 8

How to Install Java 8 on CentOS 8

Java is a widely used object-oriented programming language and software platform that runs on billions of devices, including notebook computers, mobile devices, gaming consoles, medical devices, and many others. The rules and syntax of Java are based on the C and C++ languages.

Developers use Java to construct applications in laptops, data centres, game consoles, scientific supercomputers, cell phones, and other devices. Java is the world’s third most popular programming language, after Python and C – according to the TIOBE index, which evaluates programming language popularity.

Install java 8 on CentOS 8; Through this tutorial, we will learn how to install java 8 on CentOS 8.

How to Install Java 8 on CentOS 8

Follow the following steps to install java 8 on CentOS 8:

  • Step 1 – Install Java 8
  • Step 2 – Verify Java Installation
  • Step 3 – Set Java Environment
  • Step 4 – Activate Java Environment
  • Step 5 – Test the Variables
  • Step 6 – Create a simple Java Application
  • Step 7 – Compile Java Source Code

Step 1 – Install Java 8

First of all, open the terminal or command line and execute the following command into it to install java 8 on centOS 8:

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

Step 2 – Verify Java Installation

Once the java installation is completed, then execute the following command on the command line or terminal to check the version to validate the installation of Java 8 on CentOS 8:

java -version

Step 3 – Set Java Environment

Then execute the following command on the command line or terminal to set the java environment:

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

Step 4 – Activate Java Environment

Active java environment by executing the following command on the command line or terminal to activate the java environment:

source /etc/profile.d/java8.sh

Step 5 – Test the Variables

Then test the variables by executing the following command on command line or terminal:

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

Step 6 – Create a simple Java Application

Then create a simple Java application to see Java 8 working on CentOS 8:

cat > HelloWorld.java <<EOF
public class HelloWorld {
	public static void main(String args[]) {
		System.out.println("Hello World");
	}
}
EOF

Step 7 – Compile Java Source Code

Then execute the following command on command line or terminal to compile java code:

javac HelloWorld.java

Conclusion

Install java 8 on CentOS 8; Through this tutorial, we have learned how to install java 8 on CentOS 8.

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published.