Java is a general purpose, high-level programming language developed by Sun Microsystems in 1995. Lots of application and websites that will not work unless you have Java installed. Java is fast, secure, and reliable.
In this article I will guide you how you can install the Java on CentOS 7 machine.
You can install the latest Open JDK Runtime Environment 1.8.0 using YUM command.
$ sudo yum install java-1.8.0-openjdk.x86_64
After the installation, confirm it by using the following command:
$ java -version
You will get some output like below. Above command will tell you about the Java runtime environment that you have installed.
openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
In order to help Java-based applications locate the Java virtual machine properly, you need to set two environment variables:
“JAVA_HOME” and “JRE_HOME”
$ sudo cp /etc/profile /etc/profile_backup $ echo 'export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk' | sudo tee -a /etc/profile $ echo 'export JRE_HOME=/usr/lib/jvm/jre' | sudo tee -a /etc/profile $ source /etc/profile
That’s it, now you can print them for review:
$ echo $JAVA_HOME $ echo $JRE_HOME