我写了一个简略的shell脚本用于再CentOS 7服务器上疾速装置JDK,其余版本的零碎没有试过
废话不多说间接上代码
用的是华为的JDK镜像
#!/usr/bin/env bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATH# Colorred='\033[31m'green='\033[32m'yellow='\033[33m'plain='\033[0m'get_char() { SAVEDSTTY=$(stty -g) stty -echo stty cbreak dd if=/dev/tty bs=1 count=1 2>/dev/null stty -raw stty echo stty $SAVEDSTTY}# 一些阐明clearechoecho -e "${yellow}============================================================${plain}"echo ' System Required: CentOS 7'echo ' Description: Install JDK1.8'echo ' Version: 1.0.0'echo ' Author: Jonsson <yz808@outlook.com>'echo ' Blog: https://blog.csdn.net/y1534414425'echo ' GitHub: https://github.com/jonssonyan'echo -e "${yellow}============================================================${plain}"echoecho "Press any key to start...or Press Ctrl+C to cancel"char=$(get_char)# 判断是否为root用户[[ $EUID -ne 0 ]] && echo -e "[${red}Error${plain}] This script must be run as root!" && exit 1# 判断JDK源文件是否下载过if [ ! -f "./jdk-8u202-linux-x64.tar.gz" ]; then wget https://repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gzfi# 解压JDK到指定文件夹mkdir -p /usr/local/java && tar -zxvf jdk-8u202-linux-x64.tar.gz -C /usr/local/java# 增加JDK到环境变量chmod 700 /etc/profileecho '#Java Env' >>/etc/profileecho 'export JAVA_HOME=/usr/local/java/jdk1.8.0_202' >>/etc/profileecho 'export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' >>/etc/profileecho 'export PATH=$PATH:$JAVA_HOME/bin' >>/etc/profilesource /etc/profile# 判断是否为32位零碎bit=$(getconf LONG_BIT)if [ ${bit} -eq 32 ]; then sudo yum install glibc.i686fi# 检测Java是否装置java -versionif [ $? -eq 0 ]; then echo -e "${yellow}============================================================${plain}" echo -e "${green}JDK1.8装置胜利${plain}" echo -e "${yellow}============================================================${plain}"else echo -e "${yellow}============================================================${plain}" echo -e "${red}JDK1.8装置失败,请查看你的配置${plain}" echo -e "${yellow}============================================================${plain}"fi