侧边栏壁纸
博主头像
高大北博主等级

所有的再见中,我最喜欢明天见

  • 累计撰写 208 篇文章
  • 累计创建 151 个标签
  • 累计收到 20 条评论
标签搜索

目 录CONTENT

文章目录

centos7一键离线安装脚本-jdk.18

高大北
2022-04-18 / 0 评论 / 2 点赞 / 313 阅读 / 1,091 字 / 正在检测是否收录...

使用方法

source install_jdk8.sh

install_jdk8.sh接收$1参数,可指定安装路径,默认安装路径为/usr/local

install_jdk8.sh

#!/bin/bash

current_dir=`pwd`
directory=$1

function select_installation_directory(){
  if [[ -z ${directory} ]];
  then
    directory='/usr/local'
  fi
}

function delete_default_jdk(){
  for i in $(rpm -qa | grep jdk | grep -v grep)
  do
    echo "卸载jdk -> "$i
    rpm -e --nodeps $i
  done
}

function install_jdk(){
  if [[ -n $(rpm -qa | grep jdk | grep -v grep) ]];
  then
    echo "-->卸载默认jdk失败"
  else
    tar -zxvf "${current_dir}"/jdk-8u311-linux-x64.tar.gz -C ${directory}
    #配置环境变量
    if ! grep "JAVA_HOME=${directory}/jdk1.8.0_311" /etc/profile
    then
        echo "export JAVA_HOME=${directory}/jdk1.8.0_311" >>/etc/profile
        echo -e 'export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar'>>/etc/profile
        echo -e 'export PATH=$PATH:${JAVA_HOME}/bin'>>/etc/profile
        source /etc/profile
    fi
  fi
  echo "java version:"
  java -version
}

function Main(){
  select_installation_directory;
  delete_default_jdk;
  install_jdk;
}
Main;

jdk下载地址

https://www.sky12580.cn/upload/2022/04/jdk-8u311-linux-x64.tar.gz

2

评论区