Installing Apache Tomcat on Ubuntu 18.04

Madeesha’s Tech Space
2 min readNov 2, 2018

--

Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project, you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat.

So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies. The rest of the tutorial will tell you how to install Tomcat on Ubuntu 18.04. Before executing following steps make sure you have JAVA installed in your machine.

Step 1

Create theTomcat user.

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

Step 2

Download the Tomcat archive to the /tmp directory.

cd /tmp
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.11/bin/apache-tomcat-9.0.11.tar.gz

Step 3

Then extract downloaded the Tomcat archive and move it to the /opt/tomcat directory.

sudo tar xf /tmp/apache-tomcat-9*.tar.gz -C /opt/tomcat

Step 4

Change the directory ownership to the user and the group tomcat.

sudo chown -RH tomcat: /opt/tomcat/apache-tomcat-9.0.11

Step 5

Create a unit file to run Tomcat as a service.

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

Then paste the following content in the above file.

[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/apache-tomcat-9.0.11"
Environment="CATALINA_HOME=/opt/tomcat/apache-tomcat-9.0.11"
Environment="CATALINA_PID=/opt/tomcat/apache-tomcat-9.0.11/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/apache-tomcat-9.0.11/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-9.0.11/bin/shutdown.sh
[Install]
WantedBy=multi-user.target

Do the necessary modifications to the JAVA_HOME as per your environment. If you have installed a different tomcat version, change the directory /opt/tomcat/apache-tomcat-9.0.11 accordingly.

Step 6

Start the tomcat service.

sudo systemctl daemon-reload
sudo systemctl start tomcat

Check the service status with the following command.

sudo systemctl status tomcat

If the status is active, you have successfully configured Tomcat service on your machine. Congratulations !!!

--

--

No responses yet