1.下载jdk安装包和安装脚本
下载地址:https://pan.baidu.com/s/1bo6ADQ3
其中包括:
jdk安装包:jdk-8u151-linux-x64.tar.gz
jdk一键安装脚本:install_jdk8.sh
2.安装准备
root身份登录,创建安装文件上传目录/installpkgs
# mkdir /installpkgs
上传以上下载的2个文件至该目录( /installpkgs)下
3.执行脚本
# cd /installpkgs
# chmod 755 install_jdk8.sh
# sh install_jdk8.sh
4.结果演示
以下结果则说明jdk安装成功:
附:脚本说明
#!/bin/bash #卸载环境中存在的jdk版本 for i in $(rpm -qa | grep jdk | grep -v grep) do echo "Deleting rpm -> "$i rpm -e --nodeps $i done if [[ ! -z $(rpm -qa | grep jdk | grep -v grep) ]]; then echo "-->Failed to remove the defult Jdk." else tar -zxvf /installpkgs/jdk-8u151-linux-x64.tar.gz -C /usr/local #配置环境变量 if ! grep "JAVA_HOME=/usr/local/jdk1.8.0_151" /etc/profile then echo "export JAVA_HOME=/usr/local/jdk1.8.0_151" >>/etc/profile echo -e 'export PATH=$JAVA_HOME/bin:$PATH'>>/etc/profile echo -e 'export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar'>>/etc/profile source /etc/profile fi fi echo "java version:" java -version