How to Install Apache Tomcat 10 on Ubuntu 21
Want a fresh Tomcat 10 instance running on your Ubuntu 21 machine? This guide walks you through the exact steps—no fluff, just the stuff that actually gets things up and humming.
Why Tomcat 10 on Ubuntu 21?
Tomcat 10 drops support for older servlet specs (Java EE 8) in favor of Jakarta EE 9, which means package names change from javax. to jakarta.. That shift can bite you if you’re pulling in old libraries. On a clean Ubuntu 21 install, it’s the safest route: keep everything modern and avoid those dreaded “ClassNotFoundException” surprises.
1. Install Java (OpenJDK 17)
Tomcat 10 requires at least Java 17. I’ve seen people try to run it on Java 8 and end up with cryptic errors like java.lang.UnsupportedClassVersionError. So skip the old JREs.
sudo apt update sudo apt install -y openjdk-17-jdk
Why this matters: Tomcat 10 is compiled for Java 17. Using an older JDK will stop at boot time, and you’ll have to dig through stack traces that look like they belong in a sci‑fi novel.
Verify the installation:
java -version
You should see openjdk version "17".
2. Create a Dedicated Tomcat User
Running Tomcat as root is a security no‑no, and I’ve seen “permission denied” errors when you don’t. Spin up a user that owns the Tomcat files but has no shell access:
sudo groupadd tomcat sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
3. Download and Extract Tomcat 10
Grab the latest binary from Apache’s mirrors. I prefer wget because it shows progress and won’t silently fail.
cd /tmp curl -O https://downloads.apache.org/tomcat/tomcat-10/v10.1.9/bin/apache-tomcat-10.1.9.tar.gz sudo mkdir /opt/tomcat sudo tar xzf apache-tomcat-10.1.9.tar.gz -C /opt/tomcat --strip-components=1
Why the --strip-components flag? It removes the top‑level folder so you end up with /opt/tomcat/conf, /opt/tomcat/webapps, etc., rather than a nested apache-tomcat-10.1.9/ directory.
4. Set Ownership and Permissions
Your Tomcat process needs write access to its logs and temp directories, but nobody else should be able to touch the core files.
sudo chown -R tomcat:tomcat /opt/tomcat
sudo find /opt/tomcat -type d -exec chmod 750 {} \;
sudo find /opt/tomcat -type f -exec chmod 640 {} \;
5. Create a Systemd Service File
A proper service file lets you systemctl start|stop Tomcat like any other daemon.
sudo tee /etc/systemd/system/tomcat10.service > /dev/null <<EOF [Unit] Description=Apache Tomcat 10 servlet container After=network.target [Service] Type=forking User=tomcat Group=tomcat Environment="JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid" Environment="CATALINA_BASE=/opt/tomcat" Environment="CATALINA_HOME=/opt/tomcat" ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh Restart=on-failure [Install] WantedBy=multi-user.target EOF
Why the JAVA_HOME line? Tomcat will look there for Java if you don’t set it globally. Skipping it can lead to a silent startup failure.
Reload systemd and enable the service:
sudo systemctl daemon-reload sudo systemctl enable tomcat10 sudo systemctl start tomcat10
6. Verify Tomcat is Running
Open your browser or curl:
curl http://localhost:8080/
You should see a nice “Apache Tomcat/10.1.9” welcome page. If not, check the logs in /opt/tomcat/logs/.
7. Harden Security (Optional but Recommended)
If you’re exposing Tomcat to the internet:
- Disable the default admin and manager apps until you need them.
- Use a reverse proxy like Nginx or Apache HTTPD with SSL termination.
- Keep your JDK up‑to‑date; I’ve seen outdated OpenJDKs become attack vectors.
8. Deploy Your First WAR
Just drop the .war into /opt/tomcat/webapps/. Tomcat will auto‑deploy it within a few seconds.
sudo cp /path/to/yourapp.war /opt/tomcat/webapps/
Refresh your browser to see the app appear at http://localhost:8080/yourapp.
That’s all there is to it—no fancy scripts, no needless dependencies. Now you have a clean Tomcat 10 installation on Ubuntu 21 that’s ready for production or tinkering.