How to Install Tomcat 9 on Ubuntu 20.04 LTS

In this article, We are going to perform How to Install Tomcat 9 on Ubuntu 20.04 LTS or any other cloud platform like Amazon EC2, Azure VM, Google Cloud Compute, etc.,


Apache Tomcat is an open source implementation of Java Server pages ,Java Servlet and Java Websocket Technologies developed by Apache Software foundation. It is most widely used to deploy JSP and Java Servlet applications.

Step 1: Install and verify java version

Tomcat requires Java JDK to be function, we can either install Open JDK or Oracle JAVA JDK. In this installation we have preinstalled Oracle Java 8, if you are not installed follow below link to install.

How to Download and Install Oracle Java 8 On Ubuntu 18.04/16.04 LTS


You can install openJDK

$ sudo apt install openjdk-11-jdk
$ java -version


java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

Step 2: Creating directory

First , we are creating directory before downloading and extracting tomcat 8 setup, Enter below command to create directory

$ sudo mkdir -p /opt/tomcat

Step 3: Creating tomcat user and group

We have to run tomcat with it’s own group and user without root privileges to run tomcat service. Enter below command to create group.

$ sudo groupadd tomcat

Enter below command to create user in tomcat group with /opt/tomcat directory permission .

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

Step 4: Download and Install Tomcat 9 on Ubuntu 20.04 LTS

Download the latest binary release version from tomcat 9 download page and configure it manually.

In this article we are configuring tomcat 9.0.33 version and we are using wget and unzip commands to download and extract the setup, if you don’t have installed on your system, enter below command to install.

$ sudo apt install unzip wget

Change to /tmp directory and Download the setup using below command.

$ cd /tmp
$ sudo wget

Once download is complete, you will see output like above. Unzip/extract and move to /opt/tomcat/ directory.

$ unzip apache-tomcat-*.zip
$ sudo mv apache-tomcat-9.0.33/* /opt/tomcat/

To have control on over versions and updates, we will create symbolic link latest which will point tomcat installation directory. when newer version comes and when you want to upgrade then you have to change symlink to new latest verision.

$ sudo ln -s /opt/tomcat /opt/tomcat/latest

change the directory ownership permission to user and group  tomcat.

$ sudo chown -R tomcat: /opt/tomcat

Make all scripts in the bin location executable.

$ sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'

Step 5: Configure Environment variables

Next configure environment variables using below command

$ echo "export CATALINA_HOME="/opt/tomcat"" >> ~/.bashrc

$ source ~/.bashrc

Step 6: Create Systemd unit file

To run Tomcat as a service we will create a new tomcat.service unit file in the /etc/systemd/system/ directory with the following contents:

$ sudo nano /etc/systemd/system/tomcat.service

Description=Tomcat 9 servlet container










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



Modify the value of JAVA_HOME value,If the path of your Java installation is different.

Notify systemd that we created a new unit file and start the Tomcat service by executing:

$ sudo systemctl daemon-reload
$ sudo systemctl start tomcat

You can check the service status with the below command:

$ sudo systemctl status tomcat


● tomcat.service - Tomcat 9 servlet container
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
Active: active (running) since Fri 2020-06-05 13:33:57 UTC; 5s ago
Process: 119385 ExecStart=/opt/tomcat/latest/bin/ (code=exited, status=0/SUCCESS)
Main PID: 119392 (java)
Tasks: 29 (limit: 4621)
Memory: 125.2M
CGroup: /system.slice/tomcat.service
└─119392 /opt/jdk/jdk1.8.0_251/bin/java -Djava.util.logging.config.file=/opt/tomcat/latest/conf/ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogMa

We have covered How to install tomcat 9 on Ubuntu 20.04 LTS

If there are no errors you can enable the Tomcat service to be automatically started at system startup:

$ sudo systemctl enable tomcat


Created symlink /etc/systemd/system/ → /etc/systemd/system/tomcat.service.

Step 7: Adjust the Firewall

To allow traffic on port 8080 enter the below command:

$ sudo ufw allow 8080/tcp

Step 7: Test the Installation

Open your browser and type:  http://localhost_or_IP Address:8080 If installation is successful, you will see tomcat default page like below,

tomcat 9 dashboard on ubuntu 20.04 LTS

Step 7: Start, Restart and Stop tomcat in Ubuntu

Below are commands to start,restart and stop tomcat service in ubuntu,

$ sudo systemctl start tomcat
$ sudo systemctl restart tomcat
$ sudo systemctl stop tomcat

Successfully We have performed How to Install Tomcat 9 on Ubuntu.

To learn more about Tomcat 8 features. Please refer official documentation.


In this article, We have covered install Tomcat 9 on Ubuntu 20.04 LTS, created tomcat user and group, downloaded tomcat and extracted,configured environment variables, created systemd unit file, opened firewall port.

Related Articles

How to Install Tomcat 8 on Ubuntu 18.04/16.04 LTS

Aniruddha Kanade

I am Shivdas Kanade working as Senior Site Reliability Engineer (Cloud and DevOps ). Believes in Sharing Knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap