How to Install Apache Tomcat on Ubuntu 18.04

r00t July 25, 2018

Install Apache Tomcat on Ubuntu 18.04

In this tutorial we are going to learn how to install Apache Tomcat on Ubuntu 18.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 18.04 LTS Bionic Beaver 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 18.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 -m -U -d /opt/tomcat -s /bin/false tomcat

Step 4. Installing the latest Apache Tomcat on Ubuntu 18.04 Bionic Beaver.

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-9.0.10.tar.gz
sudo mv apache-tomcat-9.0.10 /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:


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

The Tags:

Leave a Comment

Comments are closed.