How To Install Apache Tomcat 7 on CentOS 7 via Yum

Published on June 15, 2015
How To Install Apache Tomcat 7 on CentOS 7 via Yum


Apache Tomcat is a web server and servlet container that is used to serve Java applications. Tomcat is an open source implementation of the Java Servlet and JavaServer Pages technologies, released by the Apache Software Foundation.

This tutorial covers the basic installation and some configuration of Tomcat 7 with yum on your CentOS 7 server. Please note that this will install the latest release of Tomcat that is in the official Ubuntu repositories, which may or may not be the latest release of Tomcat. If you want to guarantee that you are installing the latest version of Tomcat, you can always download the latest binary distribution.

Note: Tomcat can be installed automatically on your Droplet by adding this script to its User Data when launching it. Check out this tutorial to learn more about Droplet User Data.


Before you begin with this guide, you should have a separate, non-root user account set up on your server. You can learn how to do this by completing the initial server setup for CentOS 7 tutorial. We will be using the demo user for the rest of this tutorial.

Install Tomcat

Now you are ready to install Tomcat 7. Run the following command to install the Tomcat package:

  1. sudo yum install tomcat

Answer y at the confirmation prompt to install tomcat. This will install Tomcat 7 and its dependencies, such as Java, and it will also create the tomcat user.

Most of the important Tomcat files will be located in /usr/share/tomcat. If you already have a Tomcat application that you want to run, you can place it in the /usr/share/tomcat/webapps directory, configure Tomcat, and restart the Tomcat service. In this tutorial, however, we will install a few additional packages that will help you manage your Tomcat applications and virtual hosts.

Let’s make a quick change to the Java options that Tomcat uses when it starts. Open the Tomcat configuration file:

  1. sudo vi /usr/share/tomcat/conf/tomcat.conf

Add the following JAVA_OPTS line to the file. Feel free to change the Xmx and MaxPermSize values—these settings affect how much memory Tomcat will use:

/etc/default/tomcat7 — JAVA_OPTS
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC"

Save and exit.

Note that the Tomcat service will not be running yet.

Install Admin Packages

If you are just getting started with Apache Tomcat, you will most likely want to install some admin tools that will help you deploy your Java applications and manage your virtual hosts. Luckily, there are packages that include these tools as web applications.

To install the default Tomcat root page (tomcat-webapps), and the Tomcat Web Application Manager and Virtual Host Manager (tomcat-admin-webapps), run this command:

  1. sudo yum install tomcat-webapps tomcat-admin-webapps

Answer y at the confirmation prompt.

This adds the ROOT, examples, sample, manager, and host-manager web apps to the tomcat/webapps directory.

Install Online Documentation (Optional)

If you want to install the Tomcat documentation, so that all of the links on the default Tomcat page will work, run this command:

  1. sudo yum install tomcat-docs-webapp tomcat-javadoc

Answer y at the prompt to install the documentation packages.

Configure Tomcat Web Management Interface

In order to use the manager webapp installed in the previous step, we must add a login to our Tomcat server. We will do this by editing the tomcat-users.xml file:

  1. sudo vi /usr/share/tomcat/conf/tomcat-users.xml

This file is filled with comments which describe how to configure the file. You may want to delete all the comments between the following lines, or you may leave them if you want to reference the examples:

tomcat-users.xml excerpt

You will want to add a user who can access the manager-gui and admin-gui (the management interface that we installed earlier). You can do so by defining a user similar to the example below. Be sure to change the username and password to something secure:

tomcat-users.xml — Admin User
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>

Save and exit the tomcat-users.xml file.

Now we’re ready to start the Tomcat service.

Start Tomcat

To put our changes into effect, restart the Tomcat service:

  1. sudo systemctl start tomcat

If you started the service earlier for some reason, run the restart command instead:

  1. sudo systemctl restart tomcat

Enable Tomcat Service

If you want Tomcat to run every time the server is booted up, you will need to enable the service:

  1. sudo systemctl enable tomcat

Now we’re ready to access the web interface.

Access the Web Interface

Now that Tomcat is up and running, let’s access the web management interface in a web browser. You can do this by accessing the public IP address of the server, on port 8080:

Open in web browser:

You will see something like the following image:

Tomcat root

As you can see, there are links to the admin webapps that you installed earlier.

Let’s take a look at the Manager App, accessible via the link or http://server_IP_address:8080/manager/html:

Tomcat Web Application Manager

The Web Application Manager is used to manage your Java applications. You can Start, Stop, Reload, Deploy, and Undeploy here. You can also run some diagnostics on your apps (i.e. find memory leaks). Lastly, information about your server is available at the very bottom of this page.

Now let’s take a look at the Host Manager, accessible via the link or http://server_IP_address:8080/host-manager/html/:

Tomcat Virtual Host Manager

From the Virtual Host Manager page, you can add virtual hosts to serve your applications from.


Your installation of Tomcat is complete! Your are now free to deploy your own Java web applications!

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Hi, After Installing Tomcat 7 , and start tomcat service, it failed with message:

tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2019-06-06 02:35:06 +07; 6s ago
  Process: 13299 ExecStart=/usr/libexec/tomcat/server start (code=exited, status=1/FAILURE)
 Main PID: 13299 (code=exited, status=1/FAILURE)

Jun 06 02:35:06 usercore server[13299]: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
Jun 06 02:35:06 usercore server[13299]: at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:49)
Jun 06 02:35:06 usercore server[13299]: Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
Jun 06 02:35:06 usercore server[13299]: at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
Jun 06 02:35:06 usercore server[13299]: at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
Jun 06 02:35:06 usercore server[13299]: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
Jun 06 02:35:06 usercore server[13299]: at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Jun 06 02:35:06 usercore systemd[1]: tomcat.service: main process exited, code=exited, status=1/FAILURE
Jun 06 02:35:06 usercore systemd[1]: Unit tomcat.service entered failed state.
Jun 06 02:35:06 usercore systemd[1]: tomcat.service failed.

Help me, Pls!

I am looking to install a 2nd Tomcat instance on my CentOS droplet. How would I go about doing this?

This is poorly written. For instance, does JAVA_OPTS=“-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC” go in /etc/default/tomcat7 or /usr/share/tomcat/conf/tomcat.conf ?

You say “We will be using the ‘demo’ user for the rest of this tutorial”. But the rest of the tutorial does not actually uses that username, nor explains how to tell tomcat under what user to run .


I am unable to access the tomcat manager app and host manager . I have run the sudo vi /usr/share/tomcat/conf/tomcat-users.xml command and added the code below to the file and saved it .

    <user username="admin" password="password" roles="manager-gui,admin-gui"/>

, But still , I am not able to access. and it still asks for the username and password .

@manicas Thankyou for your support, I was using Centos 6. I have rebuilt it to Centos 7 and now it is working fine.

Hi ,

I have setup the demo user . But after executing the command 'sudo yum install tomcat ’ I am getting error as ‘No package Tomcat avaliable’, where am I going wrong…?


After Installing Tomcat 7 , while running it I am reciveing a following page .please help me with that.

HTTP Status 500 - Unable to compile class for JSP:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.


org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 1 in the generated java file
The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.33 logs.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel