October 16, 2026 - 06:36
Installing Apache Tomcat Server on Ubuntu Image
Server Management

Installing Apache Tomcat Server on Ubuntu

0 Comments

Archive scope: The text below records an older manual Ubuntu 22.04 installation; do not copy it for a new deployment. Follow the Ubuntu 24.04 LTS packaged Tomcat 10.1 guide instead. The pinned old version, public 8080 access and example administrator password are not suitable for a new deployment.

Apache Tomcat is a popular open-source application server used to run Java Servlet and JSP (JavaServer Pages) applications. In this guide, I will show you how to install Apache Tomcat 10 step-by-step on Ubuntu 22.04.

1. Update the System

First, let’s update the package manager:
BASH
sudo apt update && sudo apt upgrade -y
This step installs the latest packages and security patches on your system.

2. Install Java

Apache Tomcat requires Java, so you need to install either OpenJDK or Oracle JDK. In this example, I’ll install OpenJDK. To install OpenJDK 11 or 17, run the following command:
BASH
sudo apt install openjdk-11-jdk -y
To verify the installed Java version:
BASH
java -version
If Java is not installed, you can also install OpenJDK 17 with:
BASH
sudo apt install openjdk-17-jdk -y

3. Create the Tomcat User

For security reasons, it's better to run Tomcat under a dedicated user account. Let's create a new user called tomcat:
BASH
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat

4. Download Apache Tomcat

Check and download the latest version of Tomcat from the official Apache Tomcat site:
BASH
cd /tmp
wget https://downloads.apache.org/tomcat/tomcat-10/v10.1.39/bin/apache-tomcat-10.1.39.tar.gz
Extract the downloaded archive into the /opt/tomcat directory:
BASH
sudo mkdir -p /opt/tomcat
sudo tar -xvzf apache-tomcat-10.1.39.tar.gz -C /opt/tomcat --strip-components=1
Set the correct permissions for the Tomcat directory:
BASH
sudo chown -R tomcat:tomcat /opt/tomcat
# Do not apply recursive 755; review directory and file permissions separately.

5. Start the Tomcat Service

To run Tomcat as a system service, follow these steps:
  1. Create the service file:
BASH
sudo nano /etc/systemd/system/tomcat.service
  1. Add the following content to the file:
INI
[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'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=always

[Install]
WantedBy=multi-user.target
Save and close the file (press CTRL+X, then Y and ENTER).
  1. Enable and start the Tomcat service:
BASH
sudo systemctl daemon-reload
sudo systemctl enable tomcat
sudo systemctl start tomcat
Check that Tomcat is running:
BASH
sudo systemctl status tomcat
If you see “active (running)”, Tomcat is running successfully.

6. Accessing the Tomcat Web Interface

By default, Tomcat runs on port 8080. To access the interface, open your browser and visit:
PLAINTEXT
http://localhost:8080
If you're using a remote server, replace localhost with your server’s IP address or domain name:
PLAINTEXT
http://your-server-ip:8080
If you're having trouble accessing the interface, you may need to open port 8080 in your firewall:
BASH
# Do not expose 8080 publicly; use restricted access or an SSH tunnel.

7. Enabling the Tomcat Admin Panel

To access the Tomcat Manager interface, you need to define a user. Edit the following file:
BASH
sudo nano /opt/tomcat/conf/tomcat-users.xml
Add the following lines inside the file:
XML
<role rolename='manager-gui'/>
<!-- No sample administrator password: use a unique secret and restricted management access. -->
Save the changes and restart Tomcat:
BASH
sudo systemctl restart tomcat
Then, open your browser and navigate to http://localhost:8080/manager/html to log in.

8. Enabling Tomcat to Start Automatically

To ensure Tomcat starts automatically every time your server boots up, run the following command:
BASH
sudo systemctl enable tomcat

Now Apache Tomcat is successfully running on your Ubuntu server. You can now deploy your web applications and configure Tomcat settings via the manager panel. If you encounter any issues, you can check the Tomcat logs using:
BASH
sudo journalctl -u tomcat --no-pager | tail -n 50

Related Articles

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment