LOGO

Install Tomcat 6 on Ubuntu | Step-by-Step Guide

October 11, 2007
Install Tomcat 6 on Ubuntu | Step-by-Step Guide

Installing Tomcat on Ubuntu: A Manual Guide

If you're deploying applications on Ubuntu using the Tomcat servlet container, utilizing the version available through the standard repositories is generally not recommended due to potential functionality issues. A manual installation process, as detailed below, provides a more reliable solution.

Prior to initiating the Tomcat installation, verifying the presence of Java is crucial. While it's reasonable to assume Java is already installed if you're proceeding with Tomcat, confirmation can be achieved using the following dpkg command:

dpkg --get-selections | grep sun-java

A successful Java installation will typically yield output similar to this:

sun-java6-bin install
sun-java6-jdk install
sun-java6-jre install

Should the command return no results, install the latest compatible version of Java using:

sudo apt-get install sun-java6-jdk

Tomcat Installation Steps

The installation begins with downloading and extracting the Tomcat distribution from the Apache website. It's advisable to confirm the latest version number and adjust the download link accordingly.

wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.tar.gz
tar xvzf apache-tomcat-6.0.14.tar.gz

To maintain organization, relocating the Tomcat folder to a designated permanent location is recommended. A common choice is /usr/local/tomcat, although alternative directories can be used based on preference.

sudo mv apache-tomcat-6.0.14 /usr/local/tomcat

Tomcat's operation relies on the correct setting of the JAVA_HOME environment variable. Configuring this variable within your .bashrc file is the preferred method. Alternatively, modifications can be made directly to the startup.sh file.

Editing the .bashrc file is the more robust approach. Remember that changes to this file require logging out and back into the shell to take effect.

vi ~/.bashrc

Add the following line to your .bashrc file:

export JAVA_HOME=/usr/lib/jvm/java-6-sun

With these configurations in place, Tomcat can be initiated by executing the startup.sh script located within the tomcat/bin directory.

Configuring Automatic Startup

To ensure Tomcat automatically starts upon system boot, a startup script can be created and configured. This script will also handle shutdown operations.

sudo vi /etc/init.d/tomcat

Paste the following script into the newly created file:

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun

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

Grant the script executable permissions using the chmod command:

sudo chmod 755 /etc/init.d/tomcat

Finally, establish symbolic links to integrate the script with the system's startup procedures. Execute these commands to complete the configuration:

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

With these steps completed, Tomcat should be fully installed, configured for automatic startup, and ready for operation.

#Tomcat 6#Ubuntu#installation#Java#web server#Tomcat