Some developers can do magics with Java. But even they use to have issues while installing Java in Linux. Here are the easy steps to install Java in your CentOS/Fedora/RHEL system.
Note: If you want to install Java 8, follow the tutorial – Install JAVA 8 on CentOS/Fedora/RHEL
1) Download the Source Package
You can download the latest Java 7 packages from here ( At the time of writing, the latest version is JDK 7u71, so that we will be installing that version )
For 32 Bit :
cd /opt 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/7u71-b14/jdk-7u71-linux-i586.tar.gz"
For 64 Bit :
cd /opt 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/7u71-b14/jdk-7u71-linux-x64.tar.gz"
2) Extract the archive file
For 32 Bit :
tar -xvf jdk-7u71-linux-i586.tar.gz
For 64 Bit :
tar -xvf jdk-7u71-linux-x64.tar.gz
3 ) Install and configure Java, Javac, and Jar
We will be using the “alternative” command to install and configure java, javac, and jar
cd /opt/jdk1.7.0_71/ alternatives --install /usr/bin/java java /opt/jdk1.7.0_71/bin/java 2 alternatives --config java
( alternatives –config java command will let you choose the desired Java version if you have multiple versions installed in your system. Make sure you choose the version we are installing )
alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_71/bin/javac 2 alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_71/bin/jar 2 alternatives --set javac /opt/jdk1.7.0_71/bin/javac alternatives --set jar /opt/jdk1.7.0_71/bin/jar
4) Setup Environment Variables
If you install Java-based applications such as Tomcat, you may have to configure the following environment variables.
export JAVA_HOME=/opt/jdk1.7.0_71 export JRE_HOME=/opt/jdk1.7.0_71/jre export PATH=$PATH:/opt/jdk1.7.0_71/bin:/opt/jdk1.7.0_71/jre/bin
5) Check and Verify
java -version
So that’s how you install JAVA 7 on CentOS/Fedora/RHEL.