Super Java Host
  1. Home
  2. Guides
  3. Install Tomcat on Ubuntu

Install Apache Tomcat on Ubuntu

A clean Tomcat 10.1 install on Ubuntu with OpenJDK 21, its own user, a systemd service and a heap sized for the server.

Before you start

You need an Ubuntu 22.04 or 24.04 server with root or sudo access. Pick the Tomcat line that matches your application: Tomcat 9 for javax.* applications, Tomcat 10.1 or 11 for jakarta.*. If you are not sure, read migrate Tomcat 9 to 10 first. This guide uses 10.1.

1. Install Java

sudo apt update
sudo apt install -y openjdk-21-jdk-headless
java -version

On Ubuntu 22.04 the same package exists. For Java 17 use openjdk-17-jdk-headless.

2. Create a user and download Tomcat

Never run Tomcat as root. Check the current 10.1.x number on the Tomcat download page and set it below.

sudo useradd --system --home-dir /opt/tomcat --shell /usr/sbin/nologin tomcat
TOMCAT_VERSION=10.1.XX      # replace XX with the current release
cd /tmp
curl -fSLO https://dlcdn.apache.org/tomcat/tomcat-10/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz
curl -fsSL https://downloads.apache.org/tomcat/tomcat-10/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz.sha512 | sha512sum -c -
sudo mkdir -p /opt/tomcat
sudo tar -xzf apache-tomcat-${TOMCAT_VERSION}.tar.gz -C /opt/tomcat --strip-components=1
sudo chown -R tomcat:tomcat /opt/tomcat

The checksum command must print OK. If the older release is gone from dlcdn, use archive.apache.org.

3. Remove the sample applications

sudo rm -rf /opt/tomcat/webapps/{docs,examples,host-manager,manager}

This keeps the attack surface small. Add the manager back only if you need it and restrict it to localhost.

4. Bind Tomcat to localhost

Nginx will face the internet, so Tomcat should listen only on the loopback address. In /opt/tomcat/conf/server.xml change the HTTP connector:

<Connector port="8080" protocol="HTTP/1.1"
           address="127.0.0.1"
           connectionTimeout="20000"
           redirectPort="8443" />

If Nginx passes the original protocol, add this valve inside <Host> so redirects and cookies use https:

<Valve className="org.apache.catalina.valves.RemoteIpValve"
       remoteIpHeader="X-Forwarded-For"
       protocolHeader="X-Forwarded-Proto" />

5. Create the systemd service

Set the heap from your RAM. For a 4 GB server with a database, 1.5 GB is a good start (see the JVM heap calculator).

sudo tee /etc/systemd/system/tomcat.service >/dev/null <<'EOF'
[Unit]
Description=Apache Tomcat
After=network.target

[Service]
Type=forking
User=tomcat
Group=tomcat
Environment=JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment="CATALINA_OPTS=-Xms512m -Xmx1536m -XX:+ExitOnOutOfMemoryError -Djava.awt.headless=true"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure
RestartSec=5
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now tomcat
systemctl status tomcat --no-pager
curl -I http://127.0.0.1:8080/

On ARM servers the Java path ends in arm64 instead of amd64. Check with ls /usr/lib/jvm. A 404 from Tomcat on the last line is fine: it means Tomcat answers and no application is deployed yet.

6. Put Nginx and SSL in front

Follow Nginx reverse proxy for a Java app to expose port 443 with a free Let's Encrypt certificate, then deploy your WAR file.

Common problems

  • Service fails right away: run sudo journalctl -u tomcat -n 50. A wrong JAVA_HOME is the usual cause.
  • Port 8080 already in use: sudo ss -ltnp | grep 8080 shows what holds it.
  • Killed with no error: the heap is too big for the server. Lower -Xmx or see fix OutOfMemoryError.

Prefer not to do this yourself? Every Tomcat hosting plan comes with this setup done. Start from €15.30 per month.

Last updated October 29, 2026.

Your own Java server, billed monthly

Plans from €15.30 a month. Set up for you, or run for you.