1.將jdk與tomcat安裝包與腳本放在同一目錄下java
2.使用vim 打開腳本文件在命令格式下將腳本轉成unix格式:set fileformat=unixapache
3.使用 chmod +x 腳本名.sh 將腳本文件變成可執行文件vim
4.使用source命令執行腳本 source ./腳本名.sh tomcat
注意:該腳本會刪除舊的jdk 與 tomcat,若是之前的系統須要保留,請備份後執行spa
if [ -e /usr/local/java ];then
echo "delete old exist jdk ..."
sleep 2
rm -rf /usr/local/java
echo "install new jdk ..."
mkdir /usr/local/java
sleep 2
tar zxvf jdk* -C /usr/local/java
else
mkdir /usr/local/java
tar zxvf jdk* -C /usr/local/java
fiunix
JDKPATH=`ls /usr/local/java`
echo ${JDKPATH}orm
echo " ">>/etc/profile
echo "# JDK ENV">>/etc/profile
echo "JAVA_HOME=/usr/local/java/${JDKPATH}">>/etc/profile
echo 'export JAVA_HOME=$JAVA_HOME'>>/etc/profile
echo 'export PATH=$PATH:$JAVA_HOME/bin'>>/etc/profile
if [ -e /usr/local/tomcat ];then
echo "delete old exist tomcat ..."
sleep 2
rm -rf /usr/local/tomcat
echo "install new tomcat ..."
mkdir /usr/local/tomcat
sleep 2
tar zxvf apache-tomcat* -C /usr/local/tomcat/
else
mkdir /usr/local/tomcat
tar zxvf apache-tomcat* -C /usr/local/tomcat/
fiform
echo ""
echo "source /etc/profile"
source /etc/profile
jdk