Close Menu
Technoracle
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    TechnoracleTechnoracle
    • Home
    • AWS
      • EC2
      • Lightsail
      • RDS
      • S3
    • Ubuntu
      • Ubuntu 20.04
      • Ubuntu 22.04
    • AI Tools
    • Web Hosting
    • WordPress
    • Tech News
    Technoracle
    Home - Ubuntu - Install Apache Tomcat 9 on Ubuntu 20.04[Step by Step]
    Ubuntu

    Install Apache Tomcat 9 on Ubuntu 20.04[Step by Step]

    Rajesh ShivamBy Rajesh ShivamMay 19, 2021No Comments4 Mins Read
    Install Apache Tomcat 9 on Ubuntu
    Install Apache Tomcat 9 on Ubuntu

    Apache Tomcat is an open-source technology based on Apache. It is used to deploy and server Java Server Pages(JSP), Java Expression Language, Jave WebSocket technologies. In this article, I am going to share a step-by-step guide to install Apache Tomcat 9 on Ubuntu 20.04 or other old versions such as 18.04 and 16.04.

    So let’s start

    Page Contents

    Toggle
    • How to Install Apache Tomcat 9 on Ubuntu
      • Requirement
      • Step 1: Java Installation
      • Step 2: Create Tomcat User
      • Step 3: Install Tomcat
      • Step 4: Update Permissions
      • Step 5: Create a systemd Unit File for Install Apache Tomcat 9
      • Step 6: Firewall Configuration and Test the Tomcat Server
      • Conclusion

    How to Install Apache Tomcat 9 on Ubuntu

    Requirement

    • Ubuntu system
    • Logged in user with Sudo privileges.

    Step 1: Java Installation

    Check your system if Java is already installed or not by following command.

    $ java -version

    Tomcat requires Java to be installed on the server so that any Java web application code can be executed. Install OpenJDK by running the following command.

    $ sudo apt install default-jre

    Now, Java is installed on your machine. To make sure it is installed perfectly, check Java version.

    $ java -version

    Upon successful installation, it should show latest java version.

    Check Java Version

    Step 2: Create Tomcat User

    Create a new user and group that will run the Tomcat service. First, create a new group “tomcat”.

    $ sudo groupadd tomcat

    Next, create a new tomcat user and add the user to the group “tomcat”.

    $ sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

    Now, you can download and install Tomcat.

    Step 3: Install Tomcat

    Best way to install Apache Tomcat 9 on Ubuntu by downloading the latest release and configure it manually. You can download the latest version from tomcat’s official site. To download the latest version, navigate to Binary Distributions section, then under the Core list, copy the link from the “tar.gz”.

    Now, change the directory to /tmp

    $ cd /tmp

    Now using CURL, download the Tomcat from the official website as mentioned above.

    $ curl -O https://downloads.apache.org/tomcat/tomcat-8/v8.5.66/bin/apache-tomcat-8.5.66.tar.gz

    Let’s install Tomcat under /opt/tomcat directory. Create a directory, then extract the archive to it.

    $ sudo mkdir /opt/tomcat
    $ sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1

    Now, setup the proper user permissions for installation.

    Step 4: Update Permissions

    Set permission for newly created Tomcat user. Change the directory where we already unpacked the Tomcat installation.

    $ cd /opt/tomcat

    Now, set group ownership to the entire directory.

    $ sudo chgrp -R tomcat /opt/tomcat
    $ sudo chmod -R g+r conf
    $ sudo chmod g+x conf

    Make the tomcat user the owner of the webapps, work, temp and log directories.

    $ sudo chown -R tomcat webapps/ work/ temp/ logs/

    Step 5: Create a systemd Unit File for Install Apache Tomcat 9

    To run Tomcat as a service you need to create a new unit file.

    Tomcat needs to know where Java is installed. To know Java installation location run following command.

    $ sudo update-java-alternatives -l

    Output should look like

    java-1.11.0-openjdk-amd64      1111       /usr/lib/jvm/java-1.11.0-openjdk-amd6

    The highlighted part is JAVA Home

    /usr/lib/jvm/java-1.11.0-openjdk-amd6

    Now, create systemd service file. Open a file called tomcat.service from the directory /etc/systemd/system.

    Use VI editor to edit the file and modify the JAVA Home by your JAVA Home location.

    [Unit]
    Description=Apache Tomcat Web Application Container
    After=network.target
    
    [Service]
    Type=forking
    
    Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd6
    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

    After adding the JAVA_Home, save the file followed by reload the systemd daemon so that it knows about our service file

    $ sudo systemctl daemon-reload

    Start the Tomcat service

    $ sudo systemctl start tomcat

    Step 6: Firewall Configuration and Test the Tomcat Server

    Now allow port 8080 to serve the browser request.

    $ sudo ufw allow 8080

    Now open the link with port in the broswer.

    Open in web browser
    http://server_domain_or_IP:8080

    Conclusion

    In this tutorial, you have learned how to install Apache Tomcat 9 on Ubuntu. If you like this tutorial please share this on your social media.

    ubuntu tips
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit
    Previous ArticleHow to Uninstall MySQL from Ubuntu 20.04
    Next Article How to Install phpMyAdmin on Ubuntu 20.04
    Rajesh Shivam
    • LinkedIn

    Rajesh Shivam is a seasoned professional with expertise in AWS and Linux System Administration. With over 10 years of freelancing experience, he brings a wealth of knowledge to the table. Rajesh has a strong passion for technology and stays connected with the latest happenings in the field. His dedication and expertise make him a trusted resource for all things tech-related.

    Related Posts

    linux commands every user should know in 2025
    Ubuntu 24.04

    25 Must-Know Linux Commands Every User Should Master in 2025

    Read More
    TeamViewer and Ubuntu logos on gradient background – banner for how to install TeamViewer on Ubuntu 24.04 tutorial
    Ubuntu 24.04

    How to Install TeamViewer on Ubuntu 24.04 [Fast & Easy Steps]

    Read More
    Troubleshooting ‘Permission Denied (publickey)’ SSH error on a Linux server using secure terminal access
    Ubuntu

    Fix ‘Permission Denied (publickey)’ SSH Error on Linux [Step-by-Step Guide]

    Read More
    Add A Comment
    Leave A Reply Cancel Reply

    linux commands every user should know in 2025

    25 Must-Know Linux Commands Every User Should Master in 2025

    April 10, 2025
    TeamViewer and Ubuntu logos on gradient background – banner for how to install TeamViewer on Ubuntu 24.04 tutorial

    How to Install TeamViewer on Ubuntu 24.04 [Fast & Easy Steps]

    April 10, 2025
    Troubleshooting ‘Permission Denied (publickey)’ SSH error on a Linux server using secure terminal access

    Fix ‘Permission Denied (publickey)’ SSH Error on Linux [Step-by-Step Guide]

    April 8, 2025
    Blog banner showing Ubuntu logo, coding laptop, and icons for VS Code, Docker, and Git with the title 'Perfect Dev Setup in Ubuntu 24.04 – Step-by-step guide for developers' on a dark tech-themed background.

    How to Set Up the Perfect Development Environment on Ubuntu 24.04

    April 8, 2025

    Subscribe to Blog

    Enter your email address to subscribe to
    this blog and receive notifications of new posts by email.

    Facebook X (Twitter) Instagram Pinterest
    • Sitemap
    • Privacy Policy
    • Disclaimer
    • Term of Services
    © 2025 Technoracle

    Type above and press Enter to search. Press Esc to cancel.

    Click to Copy