Tested on Ubuntu 20.04 with Apache Tomcat 9.0.62. For current releases, check the official Tomcat downloads page and update the version number accordingly.
1. What is Apache Tomcat?
Apache Tomcat is a widely used open-source web server and servlet container for publishing Java-based web applications.
2. Standard Linux OS Settings
Complete the baseline Linux preparation on your server before installing Tomcat:
Standard Configuration for Linux OS
Set the server hostname:
sudo hostnamectl set-hostname apache-tomcat-1
3. Apache Tomcat Installation Process
Install Java Runtime Environment
sudo apt update
sudo apt install -y default-jdk
java -version
dirname "$(dirname "$(readlink -f "$(which java)")")"
Create Dedicated Service User & Install Apache Tomcat
Download the archive from Apache Archive (or substitute the latest Tomcat 9/10 tarball URL from tomcat.apache.org), extract it into /opt/tomcat, and assign ownership to a dedicated unprivileged tomcat user:
sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat
mkdir -p /SETUP/
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.62/bin/apache-tomcat-9.0.62.tar.gz -P /SETUP/
sudo tar -zxvf /SETUP/apache-tomcat-9.0.62.tar.gz --directory /opt/tomcat --strip-components=1
sudo chown -R tomcat:tomcat /opt/tomcat
sudo chmod -R u+x /opt/tomcat/bin
Create the systemd Service Unit
Verify your JAVA_HOME path using the readlink command above (default-jdk on Ubuntu 22.04/24.04 installs OpenJDK 17 or 21 instead of OpenJDK 11).
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
LimitNOFILE=65535
LimitNPROC=65535
Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
[Install]
WantedBy=multi-user.target/etc/systemd/system/tomcat.service
Start and Enable the Tomcat Service
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat
sudo systemctl status tomcat
Verify the Deployment
Create a dedicated health-check JSP file (without overwriting the default ROOT/index.jsp) and verify HTTP connectivity on port 8080:
echo "<%= java.net.InetAddress.getLocalHost().getHostName() %>" | sudo -u tomcat tee /opt/tomcat/webapps/ROOT/health.jsp
curl http://<server-ip>:8080/health.jsp