Skip to content

How to Install and Configure Tomcat on Ubuntu 24.04

Steps
11
Category
Web Servers
Covers
Tomcat, Ubuntu
On this page 11 steps

Tomcat is a web server for deploying java-based web applications. It is developed and actively maintained by the Apache foundation. As of today, during updating this article Tomcat 11 is the latest version available for the installation. You can also check for the latest version on tomcat download page.

This tutorial will help you to install and configure latest Tomcat on your Ubuntu 24.04 system. You can also use the same instructions for Ubuntu 24.10 and 22.04.

Step 1 of 11Update Your System

Before installing any software, it’s important to update your system. This ensures that you have the latest security patches and package versions.

sudo apt update && sudo apt upgrade -y

This command will update the list of available packages and install any available updates for your system.

Step 2 of 11Install Java

Apache Tomcat requires Java to run. You can install the default OpenJDK package for Ubuntu, which will provide the necessary runtime environment for Tomcat.

sudo apt install default-jdk -y

After installation, you can verify that Java is installed correctly by running the following command:

java -version

If Java is installed, you should see a message similar to:


openjdk version "17.0.8"

Step 3 of 11Download Apache Tomcat 11.0.0

The next step is to download the latest version of Tomcat (version 11.0.0). You can download it directly from the Apache website or use the command below to download it via the terminal:

wget https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.0/bin/apache-tomcat-11.0.0.tar.gz

This will download the Tomcat 11.0.0 archive to your current directory.

Step 4 of 11Extract the Tomcat Archive

Now, extract the Tomcat archive to the `/opt/` directory using the following command:

sudo tar -xvzf apache-tomcat-11.0.0.tar.gz -C /opt/

This extracts Tomcat into the `/opt/` directory where third-party software is often installed. To make it easier to work with, rename the extracted folder to a simpler name:

sudo mv /opt/apache-tomcat-11.0.0 /opt/tomcat

This shortens the directory path and makes it easier to manage.

Step 5 of 11Set Up Environment Variables

To make it easier to start and manage Tomcat, you can set up environment variables. First, open your .bashrc file for editing:

nano ~/.bashrc

Then, add the following line at the end of the file:


export CATALINA_HOME=/opt/tomcat

After saving the file, apply the changes by running:

source ~/.bashrc

Step 6 of 11Start Tomcat

To start Tomcat, navigate to the `bin` directory of your Tomcat installation:

cd /opt/tomcat/bin

Then, start Tomcat using the following command:

./startup.sh

If everything is set up correctly, you should see a message indicating that Tomcat has started.

Step 7 of 11Verify Tomcat Installation

To check if Tomcat is running, open a web browser and navigate to:


http://localhost:8080

You should see the Tomcat default welcome page, confirming that the installation was successful.

Setup Tomcat on Ubuntu 24.04
Tomcat Homepage

Step 8 of 11Create Tomcat Systemd Service File

To manage Tomcat as a service, you can create a Systemd service file that helps you easily start, stop and restart Tomcat service. So first of all, create a new systemd service file:

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

Add the following content to the file:


[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/default-java
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

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

Save the file and exit.

Step 9 of 11Set Permissions

Next, create a `tomcat` user and group, and set the appropriate permissions for the Tomcat directory:

sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
sudo chown -R tomcat:tomcat /opt/tomcat

Step 10 of 11Enable and Start Tomcat Service

Finally, reload the Systemd daemon and enable the Tomcat service so that it starts automatically at boot:

sudo systemctl daemon-reload
sudo systemctl enable tomcat
sudo systemctl start tomcat

You can check the status of Tomcat using this command:

sudo systemctl status tomcat

Step 11 of 11Setup User Accounts

You need to configure tomcat users to access manager and host-manager dashboard. To do this edit the conf/tomcat-users.xml file:

sudo nano /opt/tomcat/conf/tomcat-users.xml

Now add the following content just before </tomcat-users> closing tag.


<role rolename="admin-gui"/>
<user username="admin" password="s3cret" roles="admin-gui"/>

<role rolename="manager-gui"/>
<user username="manager" password="s3cret" roles="manager-gui"/>

</tomcat-users>

Save the file and close it.

Now reestart Tomcat service to apply changes:

sudo systemctl restart tomcat

Now you can access Tomcat manager dashboard with username “manager”.

Install and Configure Tomcat on Ubuntu 24.04
Tomcat Manager Dashboard

And to access host manager authenticate with “admin” user.

Install and Configure Tomcat on Ubuntu 24.04
Tomcat Host Manager Dashboard

Conclusion

You have successfully installed and configured Apache Tomcat 11.0.0 on your Ubuntu 24.04 system. Tomcat is now ready to host your Java-based web applications, and you can easily manage its service using systemd.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top