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,
$ JAVA_HOME=/usr/java/jdk1.7.0_05 $ export JAVA_HOME $ PATH=$JAVA_HOME/bin:$PATH $ 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 $ JAVA_HOME=/usr/java/jdk1.7.0_05 $ PATH=$JAVA_HOME/bin:$PATH |
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.
If you think we have helped you or just want to support us, please consider these :-
Connect to us: Facebook | Twitter | Google Plus
Become a Supporter - Donate us some of you hard earned money: [paypal-donation]
Linux TechLab is thankful for your continued support.
Hi ,
After java installed in my centos local machine , java -version command not working. How to resolve ?
Any error ?