How to install Apache Tomcat on CentOS

Apache Tomcat is one of the most popular and powerful web application servers on Linux. You can use Tomcat to host Java servlets or JSP web applications. As with any other Apache-licensed software, Tomcat is available free of charge under liberal Apache license. If you would like to install Apache Tomcat on CentOS, here is a guide for you. For Tomcat installation on Debian or Ubuntu. refer to this guide instead.

First, you need to install Java Development Kit (JDK). To do that, set up Repoforge repository on your CentOS system, and then run the following.

$ sudo yum install java-1.6.0-openjdk-devel -y

Then, set up JAVA_HOME environment variable.

$ sudo sh -c 'echo export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk > /etc/profile.d/'
$ source /etc/profile.d/

Now download Apache Tomcat, and install it. Since Apache Tomcat is distributed as binaries, all you have to do is to copy it somewhere in your CentOS.

$ wget
$ sudo tar xvzf apache-tomcat-7.0.35.tar.gz -C /opt
$ sudo chmod +r /opt/apache-tomcat-7.0.35/conf/*

Then set up a necessary environment variable as follows.

$ sudo sh -c 'echo export CATALINA_HOME=/opt/apache-tomcat-7.0.35 > /etc/profile.d/'
$ source /etc/profile.d/

Finally, activate Tomcat by running the following startup script.

$ sudo $CATALINA_HOME/bin/

Go to http://your_centos_ip:8080 in your browser to test if Apache Tomcat is running okay. If it is, you will see the following in your browser window.

If you cannot access the above Tomcat page, make sure to stop iptables, since CentOS has iptables on by default, and it is set to block the Tomcat's default listening port 8080.

$ sudo service iptables stop
$ sudo chkconfig iptables off

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

6 thoughts on “How to install Apache Tomcat on CentOS

  1. I follow your instructions but Solr give a 404 error.
    In Tomcat admin I get this error: FAIL - Application at context path /solr-example could not be started when I try to START the application from the applications manager.

    I believe it has to do with permissions. Maybe the data directory doesn't allow Tomcat to write in it?

  2. Thanks, worked without a problem (except the download link was dead). My bash_history on a fresh CentOS 6 box (executed as root):

    yum install java-1.7.0-openjdk
    yum install java-1.7.0-openjdk-devel
    java -version
    javac -version
    echo export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86_64 > /etc/profile.d/
    source /etc/profile.d/
    tar xvzf apache-tomcat-7.0.42.tar.gz -C /opt
    chmod +r /opt/apache-tomcat-7.0.42/conf/*
    echo export CATALINA_HOME=/opt/apache-tomcat-7.0.42 > /etc/profile.d/
    source /etc/profile.d/

  3. Hello great thanks, last one week I am trying to install and configure apache tomcat!
    Finally!! I got this document .

    I have installed successfully and it's working fine

Leave a comment

Your email address will not be published. Required fields are marked *