安装包
官网下载JDK1.8安装包,如:jdk-8u301-linux-x64.tar.gz
执行脚本
创建脚本,如:install-jdk.sh
添加如下命令:
#!/bin/bash
echo "deploy jdk1.8 to centos7.6"
echo "解压缩文件"
tar -zxvf jdk-8u301-linux-x64.tar.gz
echo "jdk文件位置:/usr/local/jdk1.8"
sudo mv jdk1.8.0_301 /usr/local/jdk1.8
echo "配置环境变量"
if [ -f /etc/profile ]
then
if [ -w /etc/profile ]
then
echo "#jdk1.8 config start" >> /etc/profile
export JAVA_HOME=/usr/local/jdk1.8
export JRE_HOME=$JAVA_HOME/jre
echo "export JAVA_HOME=/usr/local/jdk1.8" >> /etc/profile
echo "export JRE_HOME=$JAVA_HOME/jre" >> /etc/profile
echo "export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib" >> /etc/profile
echo "export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin" >> /etc/profile
echo "#jdk1.8 config end" >> /etc/profile
echo "使环境变量配置生效"
source /etc/profile
java -version
elsevi
echo "profile 无写入权限"
fi
else
echo "profile is not exist"
fi
执行安装
将JDK安装包和执行脚本放在同一目录下
给执行脚本赋予可执行权限后执行即可
chmod +x install-jdk.sh
./install-jdk.sh
标签:脚本,profile,jdk1.8,JAVA,echo,etc,JDK8,HOME,centOS7.6
From: https://www.cnblogs.com/mn609/p/17325315.html