Apache Tomcat is an open-source Java application server that implements the Java Servlet, JavaServer Pages, and WebSocket specifications. It is one of the most widely used servers for running Java-based web applications in production.
This guide shows you how to install Tomcat 9 on Ubuntu 18.04, configure it as a systemd service, and set up the web management interface.
Prerequisite: You need sudo access on your Ubuntu server.
Tomcat requires Java to run. Install the default OpenJDK package:
bashsudo apt updatesudo apt install default-jdk
Running Tomcat as root is a security risk. Create a dedicated system user with a home directory at /opt/tomcat:
bashsudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat
The -s /bin/false flag prevents this user from logging in to the system directly.
Check the Tomcat 9 downloads page to confirm the latest version before running these commands.
Download the archive to the /tmp directory:
bashwget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz -P /tmp
Extract it to the /opt/tomcat directory:
bashsudo tar xf /tmp/apache-tomcat-9*.tar.gz -C /opt/tomcat
Create a symlink named latest that points to the installed version. This makes future upgrades straightforward — you only update the symlink instead of editing the service file:
bashsudo ln -s /opt/tomcat/apache-tomcat-9.0.27 /opt/tomcat/latest
Set the correct ownership and make the startup scripts executable:
bashsudo chown -RH tomcat: /opt/tomcat/latestsudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'
Create a service file so Tomcat starts automatically with the system:
bashsudo nano /etc/systemd/system/tomcat.service
Paste the following configuration:
ini[Unit]Description=Tomcat 9 servlet containerAfter=network.target[Service]Type=forkingUser=tomcatGroup=tomcatEnvironment="JAVA_HOME=/usr/lib/jvm/default-java"Environment="CATALINA_BASE=/opt/tomcat/latest"Environment="CATALINA_HOME=/opt/tomcat/latest"Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"ExecStart=/opt/tomcat/latest/bin/startup.shExecStop=/opt/tomcat/latest/bin/shutdown.sh[Install]WantedBy=multi-user.target
Reload systemd, start the Tomcat service, and enable it at boot:
bashsudo systemctl daemon-reloadsudo systemctl start tomcatsudo systemctl enable tomcat
Verify that Tomcat is running:
bashsudo systemctl status tomcat
If the output shows active (running), the service started successfully.
If UFW is active on your server, allow traffic on port 8080:
bashsudo ufw allow 8080/tcp
In production environments, it is best practice to run Tomcat behind a reverse proxy like Nginx and restrict direct access to port 8080 from external traffic.
Open http://your_server_ip:8080 in your browser. You should see the Tomcat welcome page. The Manager App is available at /manager/html and the Host Manager at /host-manager/html.
To log in to the manager apps, create an admin user in the tomcat-users.xml file:
bashsudo nano /opt/tomcat/latest/conf/tomcat-users.xml
Add these lines before the closing </tomcat-users> tag. Replace the username and password with something secure:
xml<role rolename="admin-gui"/><role rolename="manager-gui"/><user username="admin" password="admin_password" roles="admin-gui,manager-gui"/>
By default, the Manager and Host Manager apps are restricted to connections from localhost only. To allow remote access, open the context.xml file for each app and comment out the RemoteAddrValve block. You can also whitelist a specific IP address instead of removing the restriction entirely.
Restart Tomcat after any configuration change:
bashsudo systemctl restart tomcat
Tomcat 9 is now running as a managed service on your Ubuntu 18.04 server. Use the Manager dashboard to deploy, start, and stop your Java web applications. Leave a comment below if you run into any issues during setup.