自己写的脚本,存在自己服务器,不能用的话说一声


一键安装代码

wget 124.223.56.113/install_jdk17.sh && sudo sh install_jdk17.sh

install_jdkjdk17.sh内容

JDKD=/usr/local/
#设定jdk17安装目录

#检查$JDKD/jdk-17_linux-x64_bin.tar.gz文件是否存在
if [ ! -f $JDKD/jdk-17_linux-x64_bin.tar.gz ];then
    echo "----------------------------------------"
    echo "$JDKD/jdk-17_linux-x64_bin.tar.gz 文件存在"
    echo "开始下载jdk-17"
    echo "----------------------------------------"
    cd $JDKD/
    wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
    echo "jdk-17_linux-x64_bin.tar.gz 下载完成"
else
    echo "$JDKD/java 压缩包存在"
    echo "您已安装jdk-17"
fi
    echo "开始解压jdk-17_linux-x64_bin.tar.gz"
    cd $JDKD/
     tar -zxf jdk-17_linux-x64_bin.tar.gz
    #检测$JDKD/java目录是否存在
if [ -d $JDKD/java ]; then
    echo "$JDKD/java 存在"
    #删除java目录
    rm -rf $JDKD/java/*
    rmdir $JDKD/javafi
    cd $JDKD/
    mv jdk-17.0.6 java
            echo "----------------------------------------"
    echo "jdk-17解压完成"
    echo "----------------------------------------"
# 配置java环境echo "----------------------------------------"
echo "开始配置java环境"echo "添加全局变量"
echo "----------------------------------------"
grep "JAVA_HOME=$JDKD/java" /etc/profile
    if [ ! $? -eq 0 ]; then
    sed -i '$a export JAVA_HOME=$JDKD/java' /etc/profile
    sed -i '$a export PATH=$PATH:$JAVA_HOME/bin;' /etc/profile
    sed -i '$a export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar;' /etc/profile
    echo "----------------------------------------"
    echo "java环境配置完成"
    echo "----------------------------------------"
else
    echo "----------------------------------------"
    echo "java环境全局变量存在"
    echo "----------------------------------------"
fi
#检测配置是否成功
echo "----------------------------------------"
echo "检测配置是否成功"
echo "----------------------------------------"
source /etc/profile
java -version
if [ ! $? -eq 0 ]; then
    rm -rf $JDKD/java/*
    rmdir $JDKD/java
    sed -i '/export JAVA_HOME=/usr/local/java/d' /etc/profile
    sed -i '/export PATH=$PATH:$JAVA_HOME/bin;/d' /etc/profile
    sed -i '/export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar;/d' /etc/profile
    echo "============================================"
    echo "java安装失败"
    echo "已删除java环境变量"
    echo "已删除/etc/profile/java"
    echo "请尝试重新安装"
    echo "============================================"
    echo "jdk安装失败可能原因:"
    echo "已存在的jdk-17压缩包损坏"
    echo "因此建议删除已有压缩包"
else
    echo "恭喜你,安装成功了jdk-17"
fi
    java -version
if [ ! $? -eq 0 ]; then
    read -p "是否删除jdk-17压缩包(输入yes确定): " yes;
if [ "$yes" != "yes" ];then
    echo "压缩包已保留"
    echo "目录:$JDKD/jdk-17_linux-x64_bin.tar.gz"
    exit;
else
    echo "------------"
    echo "已删除jdk-17_linux-x64_bin.tar.gz"
    rm $JDKD/jdk-17_linux-x64_bin.tar.gz
    exit
fi
fi

原文地址:https://blog.csdn.net/m0_60421404/article/details/128813892

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_49777.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注