# 1. 安装JDK
tar zxf jdk-8u45-linux-x64.tar.gz
cd jdk1.8.0_45
mv jdk1.8.0_45 /usr/local/jdk
# 2. 修改所属
chown -R root.root /usr/local/jdk/
# 3. 添加环境变量
cat >> /etc/profile <<EOF
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
EOF
# 4. 环境变量生效
source /etc/profile
# 5. 测试
java -version