In this tutorial, we will show you how to install Apache Tomcat on Ubuntu 20.04 LTS. For those of you who didn’t know, Apache Tomcat is an open-source web server and servlet container developed by the Apache Software Foundation. It implements the Java Servlet, JavaServer Pages (JSP), Java Unified Expression Language, and Java WebSocket specifications from Sun Microsystems and provides a web server environment for Java code to run in.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Apache Tomcat on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
Prerequisites
- A server running one of the following operating systems: Ubuntu 20.04, 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Apache Tomcat on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Installing Java.
Run the following command to install the OpenJDK 11 JDK package:
sudo apt install openjdk-11-jdk
Once installed, we can check the version using this command:
java -version
Step 3. Installing Apache Tomcat on Ubuntu 20.04.
Check for the Tomcat server package in the repository:
sudo apt-cache search tomcat
Now download and install the tomcat9 package and the tomcat9 admin package using the following command:
sudo apt install tomcat9 tomcat9-admin
Once successfully installed it should start up automatically. You can verify it running with the ss
command. You should see an open port 8080
, as that is the default port for Apache Tomcat:
ss -ltn
You can start, stop, and restart Tomcat the same as any other systemd
service:
sudo systemctl start tomcat9 sudo systemctl stop tomcat9 sudo systemctl restart tomcat9
Step 4. Configure Firewall.
By default, Tomcat runs on port 8080
, So you need to open port 8080
to allow connections:
sudo ufw allow 8080/tcp
Step 5. Create a user for the Web Application Manager.
Now create a user for the Web Application Manager in the Tomcat Server:
sudo nano /etc/tomcat9/tomcat-users.xml
Paste the following file:
<role rolename="admin-gui"/> <role rolename="manager-gui"/> <user username="tomcat" password="pass"roles="admin-gui,manager-gui"/>
Save and close the file, then restart Tomcat Server:
sudo systemctl restart tomcat9
Step 6. Accessing Apache Tomcat on the Ubuntu system.
Tomcat server default works on port 8080. Access tomcat in the web browser by connecting your server on port 8080
, Next, enter the credentials that you gave to the new user in Tomcat Server:
http://your-ip-address:8080/manager/html
Congratulations! You have successfully installed Tomcat. Thanks for using this tutorial for installing Apache Tomcat 9 on Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you check the official Apache Tomcat website.