第一步从官网下载jdk压缩包
http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz?AuthParam=1511407032_ade69b15120bf443fd743b1b52ea4dc4
解压 tar -zxvf jdk-8u151-linux-x64.tar.gz
mv ./jdk1.8.0_151 /usr/local/jdk1.8
添加环境变量
cat>>/etc/profile<<EOF
检查环境变量
export JAVA_HOME=/usr/local/jdk1.8
export JRE_HOME=/usr/local/jdk1.8/jre
export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar:\$JRE_HOME/lib
export PATH=\$JAVA_HOME/bin:\$JRE_HOME/bin:\$PATH
EOF
source !$
java -version
出现以下信息则为成功
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)