1. 安装 OpenJDK
sudo apt-get install openjdk-6-jre
2. 检查安装是否成功
java -version #运行结果 java version "1.6.0_20" OpenJDK Runtime Environment (IcedTea6 1.9.7) (6b20-1.9.7-0ubuntu1) OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
3. 设置 JAVA_HOME 环境变量
在 ~/.bashrc 中增加下面一行
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
4. 下载和安装 Tomcat
wget http://apache.tradebit.com/pub/tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-6.0.32.tar.gz tar xvzf apache-tomcat-6.0.32.tar.gz sudo mv apache-tomcat-6.0.32 /usr/local/tomcat sudo chmod -R 755 /usr/local/tomcat
5. 让 Tomcat 在系统启动时自动运行
sudo nano /etc/init.d/tomcat
内容如下:
# Tomcat server auto-start script export JAVA_HOME=/usr/lib/jvm/java-6-openjdk case $1 in start) sh /usr/local/tomcat/bin/startup.sh ;; stop) sh /usr/local/tomcat/bin/shutdown.sh ;; restart) sh /usr/local/tomcat/bin/shutdown.sh sh /usr/local/tomcat/bin/startup.sh ;; esac exit 0
6. 设置可执行权限
sudo chmod 755 /etc/init.d/tomcat sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
7. 启动 Tomcat
sh /usr/local/tomcat/bin/startup.sh
运行结果:
Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar
8. 停止 Tomcat
sh /usr/local/tomcat/bin/shutdown.sh
当然,你也可以使用 sun-java-jdk 而不是 OpenJDK。