Skip to content

Installing Tomcat6 on Ubuntu 9.04

If you are running Ubuntu use the manual installation process shown here.

Make sure that Java is installed. Check with the dpkg command like this:

dpkg –get-selections | grep sun-java

This should give this output if java is installed on the system:

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

If no results, install the latest version with this command:

sudo apt-get install sun-java6-jdk

Installation

Now we’ll download and extract Tomcat from the apache site. Check latest version number and adjust accordingly.Replace “6.0.14″ below with the latest version number

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

Move the tomcat folder to a permanent location. Use for example /usr/local/tomcat.

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

Tomcat requires setting the JAVA_HOME variable. The best way to do this is to set it in your .bashrc file. You could also edit your startup.sh file.The better method is editing your .bashrc file and adding the bolded line there. Logout of the shell for the change to take effect. Also while you are at it, set the CATALINA_OPTS variable to whatever is suitable. Incase you have a dedicated server use a large memory allocation.

vi ~/.bashrc

If you have large amount of RAM you can set Tomcat to use minimum of 512mb and maximum of 1024mb (Like in the example below). Add the following lines:

export JAVA_HOME=/usr/lib/jvm/java-6-sun
export CATALINA_OPTS=”-Xms512m -Xmx1024m”

You could also run the JVM in server mode with the -server flag in CATALINA_OPTS. There is supposed to be a speed advantage in the server mode although it is a little slow to start up. Use the following line to run the JVM in server mode.

export CATALINA_OPTS=”-server -Xms512m -Xmx1024m”

Tomcat can be started by just executing the startup.sh script in the tomcat/bin folder.

Automatic Starting

To make tomcat automatically start when we boot up the computer, Add a script to make it auto-start and shutdown.

sudo vi /etc/init.d/tomcat

Now paste in the following:

# 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

Make the script executable by running the chmod command:

sudo chmod 755 /etc/init.d/tomcat

The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.

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

Tomcat should now be fully installed !

Setup the Manager Role

As a final step you need to login to the tomcat manager. To do that open up the tomcat/conf/tomcat-users.xml file.

sudo vi /usr/local/tomcat/conf/tomcat-users.xml

Now add the following lines at the end of the file just before the closing ‘</tomcat-users>’. Replace with your username and password at the appropriate places below.

<role rolename=”manager”/>
<user username=”your_user_name_here” password=”your_password_here” roles=”manager”/>

Now all you have to do is to restart tomcat once again.

sudo /etc/init.d/tomcat restart

Now go to the tomcat server – usually found at http://localhost:8080. Click on the link to the manager. Give the username/password you set before – and voila you can now deploy your WAR files !

*****************************************************************
*********** Follow Up 1 – RISKY step ***************************
*****************************************************************

For removing the default install of tomcat6 from ubuntu, first remove the package tomcat6 and any related packages with tomcat6 in the name via synaptic. After that type in terminal

sudo updatedb
locate tomcat6

When you get the list of all files with tomcat6 in the name, go to each of them and delete all of them one by one. That way you are sure there are no traces of the default tomcat6 install left on your system ( You may have to use root permissions to clear certain files – so be careful about what you delete)

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
This site employs the Ravatars plugin.