Friday, October 2, 2009

Install Tomcat in Ubuntu

Tomcat is a java application server. The latest version is version 6, but version 5.5 is still in wide use also. I found some information suggesting that the version in the Ubuntu repositories is broken so here is how to install it manually, no compiling required.

First you need to make sure you have Java installed. I recommend going with the development version:
$ sudo aptitude update && sudo aptitude install sun-java6-jdk
The latest version of Tomcat as of this writing is version 6.0.20. You can head over to the downloads page to get a copy of it or download using wget:
$ wget
Extract the files from the tarball:
$ tar xvzf apache-tomcat-6.0.20.tar.gz
Now you can run Tomcat from anywhere, but you probably will want to put it somewhere other than where you downloaded it to. Here is an example of somewhere to put it:
$ sudo cp -r apache-tomcat-6.0.20 /usr/local/tomcat
This command will also rename the folder from "apache-tomcat-6.0.20" to "tomcat". Next you'll need to make sure all of the binary files are executable:
$ sudo chmod +x /usr/local/tomcat/bin/*
Before you can run Tomcat, you have to specify a variable to tell it where Java is installed. If you are going to start it up manually you can put the variable in the Tomcat startup script located at "tomcat/bin/". If you are going to make a startup script in /etc/init.d/ you can put the variable in there. The variable declaration will look something like this:
export JAVA_HOME=/usr/lib/jvm/java-6-sun
Make sure this is correct on your system before you use it. I recommend creating a startup script in /etc/init.d/ for Tomcat because even if you only want to start it manually its easier to remember /etc/init.d/ because thats where most startup scripts are located. Use a text editor to save the following to "/etc/init.d/tomcat":
# /bin/sh

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

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

case $1 in
sh /usr/local/tomcat/bin/
sh /usr/local/tomcat/bin/
sh /usr/local/tomcat/bin/
sh /usr/local/tomcat/bin/
exit 0
Make the script executable:
$ sudo chmod 755 /etc/init.d/tomcat
Set the script to run automatically:
$ sudo update-rc.d -f tomcat defaults
Now you can start Tomcat by running:
$ sudo /etc/init.d/tomcat start
Or stop it by typing:
$ sudo /etc/init.d/tomcat stop
Tomcat by default listens on port 8080. You will need to make a rule in your firewall to allow this. If you are using Ubuntu's ufw, enter this command to allow connections to Tomcat:
$ sudo ufw allow 8080
You should see a Tomcat test page by navigating to:
Just replace with the IP address of the computer you just installed Tomcat onto.


  1. Really awesome post. thanks a tone for a descriptive procedure.

  2. Thank you very much. :)
    Very nicely laid out. Thanks again


Note: Only a member of this blog may post a comment.