LinuxTomcat

How to Install Tomcat in Linux (Ubuntu)

Step-by-step guide to manually installing Apache Tomcat on Linux, including download, permissions, environment variables, and startup.

25 June 2011 · 2 min read

To install Tomcat we need Java to be installed in the system. If you want to know how to install Java on Linux, you can refer to that earlier post.

We can install Tomcat either using packages (apt, yum) or manually. This post explains how to do it manually. The main advantage of doing it manually is that all the Tomcat files are in one location. The automated installation will spread the setup files across various non-standard places.

Steps

  1. Log in to the shell and navigate to the folder where you want to install Tomcat. In this example I am installing it under /usr. The shell commands are shown with # prompts (yours may show $ instead). If you are not logged in as root, prefix commands with sudo.
cd /usr
sudo mkdir tomcat7
cd tomcat7
  1. Download the zip of Tomcat files from the Tomcat website:
sudo wget http://mirror.metrocast.net/apache/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip

This will download the Tomcat zip into the tomcat7 directory. Next, unzip it:

unzip apache-tomcat-7.0.16.zip

This will create a folder named apache-tomcat-7.0.16 in the tomcat7 folder. The apache-tomcat-7.0.16 directory is your Tomcat home (CATALINA_HOME environment variable).

Setting Up Environment Variables

Both JAVA_HOME and CATALINA_HOME environment variables and their paths are required for Tomcat to run:

export CATALINA_HOME=/usr/tomcat7/apache-tomcat-7.0.16
export PATH=$PATH:$CATALINA_HOME/bin

Starting Tomcat

Before starting Tomcat, give execute permissions to the bin directory files:

cd apache-tomcat-7.0.16/bin
sudo chmod 775 *

If you run Tomcat without giving execute permissions you will get the error: “The BASEDIR environment variable is not defined correctly.”

Now start Tomcat:

sudo sh startup.sh

You can test it by opening http://localhost:8080 in the browser.