shell-安装jdk脚本
前言
在Linux安装jdk是很简单的事情,那就让shell脚本去做吧!
安装
到oracle官网的归档网址下载需要的jdk压缩包,并放到脚本所在的目录,然后cd到脚本目录执行就可以,这里是1.8.172版本为例:
http://www.oracle.com/technetwork/java/archive-139210.html
#!/bin/bash
#must run by root
if [ "$UID" != "0" ]; then
echo "Please run this script by root "
exit 1
fi
# jdk archive site
ARCHURL='http://www.oracle.com/technetwork/java/archive-139210.html'
# pacage name
JDK_PACKAGE=jdk-8u172-linux-x64.tar.gz
JDK_DIR=jdk1.8.0_172
# JDKURL="http://192.168.1.71/software/jdk-8u172-linux-x64.tar.gz"
if [ ! -f ${JDK_PACKAGE} ]
then
echo "${JDK_PACKAGE} is not exists in current dir $(pwd)"
echo "go to ${ARCHURL} site to download."
exit 1
fi
echo "Download and extense tar package ... "
if [ ! -d "/opt/jdk" ]; then
# cd /root/
# wget $JDKURL
tar ${JDK_PACKAGE} -C /opt/
cd /opt
ln -s ${JDK_DIR} jdk
else
echo "/opt/jdk already exists!"
fi
echo "Setting JAVA_HOME ... "
if cat /etc/profile | grep '#JAVA_HOME set'; then
echo "JAVA_HOME already set !"
else
echo '#JAVA_HOME set' >>/etc/profile
echo "export JAVA_HOME=/opt/jdk" >>/etc/profile
echo 'export PATH=$JAVA_HOME/bin:$PATH' >>/etc/profile
fi
echo "ok"
通过文章下面的连接可以下载到脚本