• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Source Digit

Source Digit

Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • How To
  • Ubuntu
  • Instagram
  • Blogging
  • Android
  • WordPress
  • +More
    • Cloud Computing
    • Gadgets
    • Social Media
    • Technology
  • Write for Us
Home / How To / How To Install Apache Tomcat 9 on Ubuntu

How To Install Apache Tomcat 9 on Ubuntu

By Sourabh / January 3, 2020 Category: How To, Ubuntu

How to install Apache Tomcat 9 on Ubuntu Linux. Apache Tomcat is an open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and WebSocket technologies. Tomcat provides a “pure Java” HTTP web server environment in which Java code can run

Step 1: Install Java


$ sudo apt update
$ sudo apt install default-jdk
$ java -version

Step 2: Install Apache Tomcat 8 on Ubuntu

For security purposes, Tomcat should be run as an unprivileged user (i.e. not root). We will create a new user and group that will run the Tomcat service. Run the following commands to create a new tomcat group and a new tomcat user. The user is then made a member of the tomcat group – home directory of /opt/tomcat and shell of /bin/false.


$ sudo mkdir /opt/tomcat
$ sudo groupadd tomcat
$ sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
$ cd /tmp
$ curl -O http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.30/bin/apache-tomcat-9.0.30.tar.gz
$ sudo mkdir /opt/tomcat
$ sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1

Assign Permissons to Tomcat User

Now run the following commands to assign the permissions to tomcat user. This is done because the used must access the Tomcat installation /opt/tomcat directory.

$ cd /opt/tomcat
$ sudo chgrp -R tomcat /opt/tomcat
$ sudo chmod -R g+r conf
$ sudo chmod g+x conf
$ sudo chown -R tomcat webapps/ work/ temp/ logs/

Step 3: Create a Tomcat systemd Service File

Next step is to create a new systemd service file to manage and run Tomcat as a service under systemd. To do so you must know where Java is installed – JAVA_HOME. The following steps are executed to find the JAVA_HOME.


$ sudo update-java-alternatives -l

NOTE: The JAVA_HOME variable can be extracted from the last column {highlighted in red color} and appending /jre to the end. Now, create the systemd service file. Open a file called tomcat.service in the /etc/systemd/system directory by typing the following command and append the following lines:


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

Paste the following contents into the service file.


/etc/systemd/system/tomcat.service

[Unit] Description=Apache Tomcat Web Application Container
After=network.target

[Service] Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment=’CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC’
Environment=’JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom’

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always


[Install] WantedBy=multi-user.target

When you are finished, save and close the file. Next, reload the systemd daemon:


$ sudo systemctl daemon-reload
$ sudo systemctl start tomcat
$ sudo systemctl status tomcat

Finally, run and test Tomcat. This is done in the browser by using the system’s IP address followed by the service default port 8080.


http://ip-address:8080

Primary Sidebar

Latest Posts

Job Scheduling Using At Command In Linux With Examples

How To Check Permissions Of A Directory In Linux Command

Delete Directory And Contents Recursively Without Prompt On Linux

Check User Login History In Ubuntu Linux Command Line

Use Locate Command To Find File In Linux Terminal By Name

How To Change Terminal Color In Ubuntu Command Line

How To Run Fsck Manually In Linux To Fix Unexpected Inconsistency

How To Fix Broken Packages On Ubuntu From Terminal

Re Execute The Previous Command In Linux Ubuntu Command Line

How Much RAM Is Needed For Ubuntu PC

© 2026 Source Digit • Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • About
  • Privacy Policy
  • Terms & Conditions
  • Contact Us
  • Sitemap