Skip to content

Tomcat

Date:
czw., sie 7, 2025

How can I remove tomcat 9 installation from my ubuntu

1. Remove tomcat

To remove system and config files from Ubuntu.

sudo apt-get update

sudo apt-get upgrade

sudo apt remove --purge tomcat9 tomcat9-docs

sudo apt autoremove

sudo apt autoclean

 

Locate and remove manually the remaining files if there are some

sudo apt install locate && sudo updatedb
locate tomcat

How to Install Tomcat 9 on Ubuntu 22.04

First, install OpenJDK 11.

Create a new system user and group with a home directory of /opt/tomcat to run the Tomcat service. Enter the following command:

sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat

Check the Tomcat download page to see if a newer version is available.

After that, use wget to download the Tomcat zip file to the /tmp directory:

VERSION=9.0.108

wget https://downloads.apache.org/tomcat/tomcat-9/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz

After downloading, extract the tar file to /opt/tomcat directory.

sudo tar -xf /tmp/apache-tomcat-${VERSION}.tar.gz -C /opt/tomcat/

Tomcat is typically updated regularly for security and to introduce new features. For more control, create a symbolic link called “latest” that points to the Tomcat installation directory.

sudo ln -s /opt/tomcat/apache-tomcat-${VERSION} /opt/tomcat/latest

Unpack the latest version, then update the symlink to point to it. Additionally, change the directory ownership to the user and group tomcat using:

sudo chown -R tomcat: /opt/tomcat

After that, the shell scripts in Tomcat's bin directory need to be made executable.

sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'

 

Open the text editor and create a tomcat.service unit file in the /etc/systemd/system/ directory.

sudo nano /etc/systemd/system/tomcat.service

2) After that, paste the following configuration in /etc/systemd/system/tomcat.service:

/etc/systemd/system/tomcat.service
[Unit]
Description=Tomcat 9 servlet container
After=network.target
[Service]
Type=forking User=tomcat Group=tomcat Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64" Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true" 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.sh ExecStop=/opt/tomcat/latest/bin/shutdown.sh [Install] WantedBy=multi-user.target

Then, save and close the file. Notify systemd that a new file exists.

sudo systemctl daemon-reload

4) Once done, enable the Tomcat service and start it.

sudo systemctl enable --now tomcat

5) You will need to check the service status.

sudo systemctl status tomcat

Configure the Firewall

If you wish to access Tomcat from outside the local network, you must open port 8080. To do so, use the following command:

sudo ufw allow 8080/tcp