CentOS - Tomcat 6

This tutorial will walk you through installing Tomcat 6 on CentOS 5. This installation assumes you have walked through the CentOS - Setup article.


Acquiring JRE/JDK

First we need to download JDK and JRE 6 for CentOS. Download the following files to your root directory (~) with 'wget'. Note that you may need to change the file names as they may have some URL variables added to the name. Be sure to *not* download the RPM files.

JDK Download

JRE Download


Now that we have the files downloaded we need to create an installation directory for Java.

sudo mkdir /usr/java
cd /usr/java

Now we need to execute the installation for Java Development Kit (JDK). In our example we will use specific file names. Keep in mind that your file names may vary.

sudo sh ~/jdk-6u14-ea-bin-b03-linux-amd64-10_mar_2009.bin

Press <space> to advance through the license agreement and type 'yes' to accept. Press <enter> to finish the installation.

Now we need to install the Java Runtime Edition (JRE). In our example we will use specific file names. Keep in mind that your file names may vary.

sudo sh ~/jre-6u14-ea-bin-b03-linux-amd64-10_mar_2009.bin

Press <space> to advance through the license agreement and type 'yes' to accept.

Verify the installation by typing ls. You should see two directories: jdk1.6.0_14 and jre1.6.0_14. Keep in mind that your version numbers may differ slightly.

Installing Ant and Tomcat

Next we will need to download and extract Apache Ant. Ant is an installation utility used by several Apache products.

To download Apache Ant you will need to visit the following website to download the installation file: http://ant.apache.org/bindownload.cgi. Scroll down the page and find the .tar.gz under Current Release of Ant. Copy the URL and use wget to download the file to the /usr/share directory. Your version number may differ.

cd /usr/share
sudo wget http://mirror.olnevhost.net/pub/apache/ant/binaries/apache-ant-1.7.1-bin.tar.gz

Next we need to unpack that file so we can install it. Note that your version number may be different.

sudo tar -xzf apache-ant-1.7.1-bin.tar.gz

Now we need to download Tomcat 6 to the /usr/share directory. Go to http://tomcat.apache.org/download-60.cgi and download the latest Core version. This will be located under the 'Binary Distributions' portion. Be sure to download the tar.gz package. Note that the version numbers may vary.

cd /usr/share
sudo wget http://apache.ziply.com/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz

Now we need to unpack that archive. Note that your version number may be different.

sudo tar -xzf apache-tomcat-6.0.18.tar.gz

We need to create a symbolic link for Ant so other applications can easily find it. Be sure to select the correct version when you create your link.

sudo ln -s /usr/share/apache-ant-1.7.1/bin/ant /usr/bin


We need to setup the JAVA_HOME environment variable so Tomcat can find Java. Be sure to change the directory name according to your version of Tomcat.

cd /usr/share/apache-tomcat-6.0.18/bin
sudo vi catalina.sh

This will bring up the vi window. After the first line (that reads #!/bin/sh) you need to add a new line. To insert a new line press the i key to enter insert mode. Enter the following:


** Be sure to adjust the directory name according to your JDK version **

Save the file by pressing the colon (:) key, typing wq, and then pressing <enter>.

Now it is time to test your Tomcat installation. Be sure to note the version number in your path.

cd /usr/share/apache-tomcat-6.0.18/bin
sudo ./startup.sh

If it successfully starts you should see something similar to this:

Using CATALINA_BASE:   /usr/share/apache-tomcat-6.0.18
Using CATALINA_HOME:   /usr/share/apache-tomcat-6.0.18
Using CATALINA_TMPDIR: /usr/share/apache-tomcat-6.0.18/temp
Using JRE_HOME:       /usr/java/jdk1.6.0_14

If you want to check for errors you can run the following command:

less /usr/share/apache-tomcat-6.0.18/logs/catalina.out

To verify your Tomcat installation is working go to in your web browser. Be sure to change to your server's IP address.

Automating Startup

Right now Tomcat will not start up on it's own so we need to create a startup script for this. To do this:

cd /etc/init.d
sudo vi tomcat

Press i to enter insert mode and paste in the following:

    # chkconfig: 234 20 80
    # description: Tomcat Server basic start/shutdown script
    # processname: tomcat
    export JAVA_HOME
    start() {
    echo -n "Starting tomcat: "
    echo "done."
    stop() {
    echo -n "Shutting down tomcat: "
    echo "done."
    case "$1" in
    sleep 10
    echo "Usage: $0 {start|stop|restart}"
    exit 0
Be sure to change the following items in the above file:
* JAVA_HOME path

Once you have those changes made, save the file and quit.

Now we need to change the permissions on the file.

sudo chmod 755 tomcat

We need to set the script to start with other system services and set the runlevels.

sudo /sbin/chkconfig --add tomcat
sudo /sbin/chkconfig --level 234 tomcat on

You can verify that it is listed by typing /sbin/chkconfig --list tomcat.

tomcat         	0:off	1:off	2:on	3:on	4:on	5:off	6:off

Test your shutdown and startup script.

sudo /sbin/service tomcat stop
sudo /sbin/service tomcat start

Tomcat 6 should now be installed under CentOS.

--Kelly Koehn 11:48, 25 March 2009 (CDT)

Was this content helpful?

© 2015 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER