DEV Community

Cover image for How to install Apache Tomcat 9 on Ubuntu 20.04 LTS
Dhanusha Perera
Dhanusha Perera

Posted on

How to install Apache Tomcat 9 on Ubuntu 20.04 LTS

About This Article

This article is about how to install Apache Tomcat 9 using 'tar.gz' on Ubuntu 20.04 LTS. Hope you will learn something. Cheers!

 

Prerequisite

You need to have Java 8 installed on your machine.
Tomcat 9 works on only Java 8. More Information.

You can confirm the java version with the following command.

java -version
Enter fullscreen mode Exit fullscreen mode

 

Let's install Apache Tomcat 9

  1. Visit Apache Tomcat Site.
  2. Download Apache Tomcat 9.

    • Download tar.gz (pgp, sha512) the Core Binary Distributions of the Apache Tomcat.
  3. Open up your terminal and cd into the directory where you have downloaded the Apache Tomcat tar.gz file.

Tip: You can open up the terminal by pressing Ctrl + Alt + T on your keyboard.

cd /home/<type-username-here>/Downloads
Enter fullscreen mode Exit fullscreen mode
  1. Extract the tar.gz file to /opt directory with the following command.
sudo tar -xf apache-tomcat-9.0.55.tar.gz -C /opt
Enter fullscreen mode Exit fullscreen mode

 

Setting up the Catalina environment variable.

  1. Let's cd into the Tomcat directory.
cd /opt/apache-tomcat-9.0.55/
Enter fullscreen mode Exit fullscreen mode
  1. You can see the current directory by running the following command. Copy the path of the current directory. This is the path of the tomcat 9.
pwd
Enter fullscreen mode Exit fullscreen mode
  1. Now open up the terminal and type the following command to get the root access. You will need to provide the password if needed.
sudo su
Enter fullscreen mode Exit fullscreen mode
  1. Open up the ~/.bashrc file using gedit and the Catalina environment variable.
gedit ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  1. Scroll down to the end of the document and set the Catalina environment variable. /opt/apache-tomcat-9.0.55 is the path of the tomcat which you copied earlier.
export CATALINA_HOME=/opt/apache-tomcat-9.0.55
Enter fullscreen mode Exit fullscreen mode
  1. Save the ~/.bashrc file and close gedit window.

 

Run Tomcat 9

  1. You can run Tomcat 9 by running the following command.
sh startup.sh
Enter fullscreen mode Exit fullscreen mode
  1. Now you can open up a web browser and navigate to the tomcat URL. If you can see the Tomcat initial page. Then you have successfully installed and the tomcat 9 server is up and running.
http://localhost:8080/
Enter fullscreen mode Exit fullscreen mode
  1. If you want to shut down the Tomcat server, you can do so by running the following command.
sh shutdown.sh
Enter fullscreen mode Exit fullscreen mode

 
Below you can find a screenshot of my terminal.

Screenshot of the terminal

Top comments (0)