How to Install Apache Tomcat on Ubuntu 16.04

r00t December 23, 2017

Install Apache Tomcat on Ubuntu 16.04

In this tutorial we will show you how to install Apache Tomcat on Ubuntu 16.04. We will also install and configure its prerequisites. 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, published by the Apache Software Foundation.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 16.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Apache Tomcat on Ubuntu 16.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing Java.

Apache Solr is written in Java application, so Java runtime environment needs to be installed:

apt install python-software-properties
add-apt-repository ppa:webupd8team/java

We will install the latest version of Oracle Java 8:

apt-get update -y
apt-get install oracle-java8-installer

After installation, you can verify the version by running:

java -version

Step 3. Create Tomcat Group and User.

Tomcat should not be run as root user. So, create a normal user for running the Tomcat service:

sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Step 4. Installing the latest Apache Tomcat.

First, download the latest version of the Apache Tomcat from the website:


Then extract the Tomcat archive and move it to your desired (/opt/tomcat) directory:

sudo tar -xzvf apache-tomcat-8.5.12.tar.gz
sudo mv apache-tomcat-8.5.12 /opt/tomcat

Now change the proper ownership using following command:

sudo chgrp -R tomcat /opt/tomcat
sudo chown -R tomcat /opt/tomcat
sudo chmod -R 755 /opt/tomcat

Step 5. Create a Systemd Service File.

Now you will need to create a systemd service file to manage the Tomcat process so you can run Tomcat as a service:

nano /etc/systemd/system/tomcat.service

Add the following content:

Description=Apache Tomcat Web Server


Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'




Reload the systemd daemon, then start and add the Apache Tomcat service at boot time:

systemctl daemon-reload
systemctl start tomcat
systemctl enable tomcat

Step 6. Configure Firewall.

In order to test Apache Tomcat in a web browser, you need to modify the firewall rules:

sudo ufw allow 8080

Step 7. Configure Tomcat Web Management Interface.

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

nano /opt/tomcat/conf/tomcat-users.xml

Place the following two lines just above the last line:

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

Restart Apache Tomcat to put your modifications into effect:

systemctl restart tomcat

Step 8. Accesing Apache Tomcat.

The Apache Tomcat is now accessible on the default port, which is 8080. The admin UI should be accessible at http://your_server_ip:8080/solr.

Congratulation’s! You have successfully install and configured Apache Tomcat on your Ubuntu 16.04 server. Thanks for using this tutorial installing Apache Tomcat on Ubuntu 16.04 LTS (Xenial Xerus) system.

The Tags:

Leave a Comment

Comments are closed.