今天刚写的一个linux下的JDK和TOMCAT一步安装的shell脚本
JDK安装在/usr/java目录下,tomcat安装在/usr/local目录下,如果目录不存在会自动创建,只需把jdk和tomcat的tar包和脚本放在同一目录下,执行脚本就可以了。
PS:此脚本可以重复执行,重复执行会自动删除上次安装的jdk和tomcat目录
01
#!/bin/sh
02
03
if [ -e /usr/java ];then
04
echo "delete old exist jdk ..."
05
sleep 2
06
rm -rf /usr/java
07
echo "install new jdk ..."
08
mkdir /usr/java
09
sleep 2
10
tar zxvf jdk* -C /usr/java
11
else
12
mkdir /usr/java
13
tar zxvf jdk* -C /usr/java
14
fi
15
16
JDKPATH=`ls /usr/java`
17
echo ${JDKPATH}
18
19
echo " ">>/etc/profile
20
echo "# JDK ENV">>/etc/profile
21
echo "JAVA_HOME=/usr/java/${JDKPATH}">>/etc/profile
22
echo 'PATH=$JAVA_HOME/bin:$PATH'>>/etc/profile
23
echo 'CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar'>>/etc/profile
24
echo 'export JAVA_HOME'>>/etc/profile
25
echo 'export PATH'>>/etc/profile
26
echo 'export CLASSPATH'>>/etc/profile
27
28
if [ -e /usr/local/apache-tomcat* ];then
29
echo "delete old exist tomcat ..."
30
sleep 2
31
rm -rf /usr/local/apache-tomcat*
32
echo "install new tomcat ..."
33
sleep 2
34
tar zxvf apache-tomcat* -C /usr/local
35
else
36
tar zxvf apache-tomcat* -C /usr/local
37
fi
38
39
cd /usr/local/apache-tomcat*
40
TOMCATPATH=`pwd`
41
echo ${TOMCATPATH}
42
43
echo " ">>/etc/profile
44
echo "# TOMCAT ENV">>/etc/profile
45
echo "TOMCAT_HOME=${TOMCATPATH}">>/etc/profile
46
echo 'PATH=$TOMCAT_HOME/bin:$PATH'>>/etc/profile
最后在执行一下
source /etc/profile
让环境变量生效就可以了