Your cart is currently empty!
How to install Apache Tomcat on Ubuntu
If you’re running Java web apps, Apache Tomcat is a go-to server. Lightweight, reliable, and open source—Tomcat powers countless production environments. In this guide, I’ll walk you through installing Apache Tomcat on an Ubuntu system. No fluff. Just the steps.
Prerequisites
Before we start, make sure you have:
- Ubuntu 20.04 or newer
- A user with sudo privileges
- Java installed
Let’s get into it.
Step 1: Install Java
Tomcat runs on Java, so first make sure it’s installed.
sudo apt update
sudo apt install default-jdk -y
Verify installation:
java -version
You should see output like:
openjdk version "11.0.x" ...
Step 2: Create a Tomcat User
It’s best practice not to run Tomcat as root.
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
Step 3: Download Tomcat
Head to the Tomcat download page and grab the latest version. Use wget
to download it:
cd /tmp
wget https://downloads.apache.org/tomcat/tomcat-10/v10.1.XX/bin/apache-tomcat-10.1.XX.tar.gz
Replace 10.1.XX
with the current version number.
Extract and move it to /opt/tomcat
:
sudo mkdir /opt/tomcat
sudo tar -xzvf apache-tomcat-10.1.XX.tar.gz -C /opt/tomcat --strip-components=1
Step 4: Set Permissions
Give the Tomcat user access:
sudo chown -R tomcat: /opt/tomcat
sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh'
Step 5: Create a Systemd Service
We’ll set Tomcat up as a service so it can start at boot.
Create the service file:
sudo nano /etc/systemd/system/tomcat.service
Paste this in:
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Save and close.
Reload the daemon and start Tomcat:
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat
Check the status:
sudo systemctl status tomcat
Step 6: Access the Tomcat Web Interface
Tomcat should be running on port 8080. Open a browser and visit:
https://your_server_ip:8080
You’ll see the default Tomcat homepage.
Optional: Enable the Admin UI
Want to use the Tomcat Manager or Host Manager apps? You’ll need to add a user.
Edit tomcat-users.xml
:
sudo nano /opt/tomcat/conf/tomcat-users.xml
Add this inside the <tomcat-users>
tag:
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="admin" password="your_password" roles="manager-gui,admin-gui"/>
Then restart Tomcat:
sudo systemctl restart tomcat
Now you can access:
- Manager:
https://your_server_ip:8080/manager/html
- Host Manager:
https://your_server_ip:8080/host-manager/html
Use the credentials you just set up.
That’s It
You’ve got Apache Tomcat running on Ubuntu. From here, you can deploy your Java web applications and start configuring the server for production.
Have questions or run into issues? Drop a comment below.