shell脚本安装
脚本名称
install-jdk17.sh
脚本内容:
#!/bin/bash
# 下载JDK 17的安装包
wget https://download.java.net/java/GA/jdk17.0.1/2a2082e5a09d4267845be086888add4f/12/GPL/openjdk-17.0.1_linux-x64_bin.tar.gz
# 解压安装包
tar zxvf openjdk-17.0.1_linux-x64_bin.tar.gz
# 移动JDK到/usr/lib目录下
mv jdk-17.0.1 /usr/lib
# 配置环境变量 位置1 ~/.bashrc 位置2 /etc/profile 本文采用位置2
echo "export JAVA_HOME=/usr/lib/jdk-17.0.1" >> /etc/profile
echo "export CLASSPATH=$JAVA_HOME/lib" >> /etc/profile
echo "export PATH=${PATH}:${JAVA_HOME}/bin" >> /etc/profile
# 更新环境变量
source /etc/profile
# 验证安装
java -version