How to setup apache tomcat

In this article you will learn how install and setup apache tomcat under Linux / UNIX environments.


Before we begin installation of Apache tomcat on our Debian based operating system Ubuntu 12.04 LTS, you need to make sure that your hostname is correctly setup.


Note: This works under Ubuntu 10.04 LTS, Ubuntu 13, CentOS / RHEL / Redhat Enterprise Linux, Debian 6 and Debian 7.


If you don’t know on how to set your machine hostname please refer to our previous article “How to setup hostname.”


In our case, our hostname is “”


First, update your operating system’s repositories and then upgrade the packages installed. Please note we are running all commands from a sudo enabled user.


sudo apt-get update

sudo apt-get upgrade

What is Apache Tomcat?

Apache tomcat is a JAVA based web application server. It is one of the most widely used JAVA server and it is a web server and a servlet container for Java web applications.


The latest stable release of Apache Tomcat at the time of writing this article is 7 (May 2013). We will be using latest tarball from the Apache website.

We strongly recommend checking the Apache Tomcat website when installing as installing latest stable version has a lot of security and bug fixes which will help stabilize the server as well as the web application.


We will cover both installations automated installation using “apt-get” and installation from the tarball archive which is available on Apache Tomcat and this applies to other distributions as well “CentOS / RHEL / Redhat Enterprise Linux”


To download and install Apache Tomcat 7 under Debian / Ubuntu:

sudo apt-get install tomcat7

To download and install Apache Tomcat 7 CentOS / RHEL / Redhat Enterprise Linux:


You can download latest stable version of Apache Tomcat from their website:


Please remember to download tar.gz under the “Core” section of the download page.


We will download the latest stable tarball of Apache Tomcat 7


cd ~


As the download completes, extract the tarball


tar xvzf apache-tomcat-7.0.40.tar.gz


If you want to run Apache Tomcat 7 under your home directory “~” you may remain this as it is. However if you want to run under some specific directory, you need to make it now before installation.


In this article we are moving our installation to the “/opt/” directory


sudo mv apache-tomcat-7.0.40 /opt/tomcat


We have now installed entire Apache tomcat 7 web server under /opt/tomcat directory. Before you start it, deploy it, or test any application, you need to install Java. This is because Apache Tomcat needs it to start or deploy any web application written in JAVA language.


To install Java:

sudo apt-get install default-jdk


Once JAVA (above) is installed, you need to edit your file toyou’re your environment variables. We are doing that for our user, if you intend to use any other user you need to do it for the users specific “.bashrc” file or you need to set the environment variables globally for the all the users of the operating system.


vim ~/.bashrc


Add below content to the end of the file “.bashrc”


export JAVA_HOME=/usr/lib/jvm/default-java

export CATALINA_HOME=/opt/tomcat


Save and exit the file “.bashrc”

We either need to log out and log in again to make the changes took effect, or you can restart the .bashrc file by using the command below.


. ~/.bashrc


Tomcat is now installed and configured on your machine / server but it is not yet started.

To start Apache Tomcat 7 web server use commands below:



Now we go to the web browser and navigate to you rip address; in our case it is “” our URL is below:


Why port 8080?

Apache Tomcat 7 web server’s default port is 8080. However you may change this to something else which is not the scope of this article.


This will show us the default page of the Apache Tomcat 7. If you see the default page it will be saying “If you see this page this means that you have successfully installed Apache Tomcat 7”

Great, You just installed and configured Apache Tomcat 7 Web server!

In next article we will cover how to deploy web applications under Apache Tomcat 7 web server.

Posted in
Last update:
2015-12-03 20:39
Average rating:0 (0 Votes)