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
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
BASH
java -version
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
/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
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:- Create the service file:
BASH
sudo nano /etc/systemd/system/tomcat.service
- 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
- Enable and start the Tomcat service:
BASH
sudo systemctl daemon-reload
sudo systemctl enable tomcat
sudo systemctl start tomcat
BASH
sudo systemctl status tomcat
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
PLAINTEXT
http://your-server-ip:8080
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
XML
<role rolename='manager-gui'/>
<!-- No sample administrator password: use a unique secret and restricted management access. -->
BASH
sudo systemctl restart tomcat
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!