Installing Java on CentOS
Here I am going to explain how to install Open JDK Java 7 and Java 8 on CentOS. First, we need to install relevant JDK and JRE versions on your machine.
If you need to install Java 8, you can run following two commands on your machine:
sudo yum install java-1.8.0-openjdksudo yum install java-1.8.0-openjdk-devel
If you need to install Java 7, run following two commands:
sudo yum install java-1.7.0-openjdksudo yum install java-1.7.0-openjdk-devel
Then we need to identify the java home to set the JAVA_HOME environment variable. Therefore you need to run following command to identify the correct java_home. You can see the output as follows:
Now you can extract the java path from the above output and set the java_home as follows:
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171–2.6.13.0.el7_4.x86_64/jre
then export the PATH variable:
export PATH=$PATH:$JAVA_HOME/bin
Now you have installed java on CentOS successfully :)