下载JDK

Java SE 8的官方网址

jdk下载路径 点击下载

image

解压文件

tar -xvf jdk-8u65-linux-x64.tar.gz

添加环境变量

echo " ">>/etc/profile
echo "# Made for java env by chenqi on $(date +%F)">>/etc/profile
echo 'export JAVA_HOME=/usr/local/java'>>/etc/profile
echo 'export JRE_HOME=${JAVA_HOME}/jre'>>/etc/profile
echo 'export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib'>>/etc/profile
echo 'export PATH=${JAVA_HOME}/bin:$PATH'>>/etc/profile
tail -4 /etc/profile
source /etc/profile
echo $PATH

环境变量生效

source /etc/profile

检查安装是否成功

java -version

image

centeros 卸载自带的openjdk

# 查询安装的jdk
rpm -qa|grep java

rpm -e --nodeps挨个卸载

image

rpm -e --nodeps java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64