查看是否安装过jdk
java -version
-bash: java: command not found
卸载jdk
apt-get remove openjdk*
下载jdk安装包
wget https://mirrors.huaweicloud.com/java/jdk/8u151-b12/jdk-8u151-linux-x64.tar.gz
mkdir -p /usr/java/jdk
将安装包移动到/usr/java/jdk
cp jdk-8u151-linux-x64.tar.gz /usr/java/jdk/
进入/usr/java/jdk
cd /usr/java/jdk
tar -xvf jdk-8u151-linux-x64.tar.gz
编辑环境变量
vi /etc/profile
复制以下内容到profile,注意jdk的版本目录
export JAVA_HOME=/usr/java/jdk/jdk1.8.0_151
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
接下来输入命令使profile的配置生效【一定要先进入etc再来执行source profile】
cd /etc
source profile
验证是否安装成功
java -version
安装成功!!!!!!!!!!!!