Install Java 8 on centos
This article describes how to install and update java8.
1. Reading Guide
After a long wait, Java SE Development Kit 8 can finally be downloaded. JDK8 integrates many enhanced features and is officially released on July 8, March 18, 2014. You can find all the functions here.
2. download the latest JDK version.
You can directly download the latest version from the Oracle official website, or you can run the following command through shell to download it:
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/8u72-b15/jdk-8u72-linux-x64.tar.gz" -O jdk-8u72-linux-x64.tar.gztar xzf jdk-8u72-linux-x64.tar.gz
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/8u72-b15/jdk-8u72-linux-i586.tar.gz" -O jdk-8u72-linux-i586.tar.gztar xzf jdk-8u72-linux-i586.tar.gz
3. Use the Alternatives command to install JAVA
After the installation package is decompressed, you can use the alternatives command for installation. The alternatives command encapsulates chkconfig.
cd /opt/jdk1.8.0_72/alternatives --install /usr/bin/java java /opt/jdk1.8.0_72/bin/java 2alternatives --config javaThere are 3 programs which provide 'java'. Selection Command-----------------------------------------------* 1 /opt/jdk1.7.0_71/bin/java + 2 /opt/jdk1.8.0_45/bin/java 3 /opt/jdk1.8.0_66/bin/java 4 /opt/jdk1.8.0_72/bin/javaEnter to keep the current selection[+], or type selection number: 4
Java 8 has been successfully installed on your system. In addition, we recommend that you use alternatives to set the execution paths of javac and jar.
alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_72/bin/jar 2alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_72/bin/javac 2alternatives --set jar /opt/jdk1.8.0_72/bin/jaralternatives --set javac /opt/jdk1.8.0_72/bin/javac
4. view the installed JAVA version
Run the following code to view the installed JAVA version
java -versionjava version "1.8.0_72"Java(TM) SE Runtime Environment (build 1.8.0_72-b15)Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)
5. Set Environment Variables
Most JAVA applications need to set environment variables to run. You can use the following command to set them:
Set JAVA_HOME variable
export JAVA_HOME=/opt/jdk1.8.0_72
Set JRE_HOME variable
export JRE_HOME=/opt/jdk1.8.0_72/jre
Set the PATH variable
export PATH=$PATH:/opt/jdk1.8.0_72/bin:/opt/jdk1.8.0_72/jre/bin
The preceding environment variables can be placed in the/etc/environment file, and will be automatically loaded at system startup.
6. JDK 7
For 64-bit
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.tar.gz" -O jdk-7u80-linux.tar.gz
For 32-bit
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-i586.tar.gz" -O jdk-7u80-linux-i586.tar.gz