Installing JAVA 7 & 8 on Centos/RHEL 7
Last updated on March 12th, 2018 at 09:23 pm
Java is a programming language which is used on lots of websites, applications & requires java to be installed on system in order for them to completely work on the system. It comes in two packages, JDK(Java Development Kit) & JRE (Java runtime environment). JDK is used for development, monitoring &deploying purposes& also contains JRE packages while JRE is used for deploying java application s only.
In this tutorial, we are going to install java 7 & 8 on CentOS/RHEL 7 machines.
(Recommended Read:Complete guide for Apache TOMCAT installation on Linux )
Installing Java 7
We can either use yum or download a rpm package for installing java 7 on the machine. To install java 7 using yum, run
|$ yum install java-1.7.0-openjdk-devel|
& to install java using rpm, we need to download rpm package for java 7. Run the following command to download rpm file for version 7,
|$ wget –no-cookies –no-check-certificate –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” http://download.oracle.com/otn-pub/java/jdk/7u80-b15/jdk-7u80-linux-x64.rpm|
Once rpm package has been downloaded, install it by running
|$ rpm –ivh jdk-7u80-linux-x64.rpm|
Installing Java 8
For installing java 8, we need to get the rpm package . Run the following to obtain the package,
|$ wget –no-cookies –no-check-certificate –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.rpm|
& install it using rpm command, as we did above,
|$ rpm –ivh jdk-8u112-linux-x64.rpm|
(Recommended read: RPM commands with example)
Note :- After installation of java, we check the version by running
|$ java –version|
Setting Java Environment variables
Java variables, mainly JAVA_HOME & JRE_HOME, are used by many java applications to determine which java executable to use. So we need to set these variables as environment variables. To do so, we can run,
$ export JAVA_HOME
$ export PATH
But these variables will saved for current session only & will need to configured after every reboot. To set them permanently permanantly add them to .bashrc file
|$ vi .bashrc|
Similarly we can add JRE_HOME variable to the file.
Note– Change the home path & version number as per your installation.
So this completes our tutorial. Please leave any queries in the comment section below.