This tutorial is a step-by-step guide to download Tomcat 9.0.45. The code here was tested on Debian 10. That means that if you’re using any Debian-based distro like Ubuntu or Kali Linux (or Debian itself), you can follow through.

Prerequisites for Apache Tomcat 9

You need to be a user with sudo privileges. If you are not a sudo/root user, you can do as follows to get that user privilege:

a) Create a new user

Login as root and in your terminal enter the following command:

You will be prompted to give a password. Ensure that it is strong and secure. You will also be asked for additional info like your name and telephone number. This is optional and trivial. You can just press the enter key to skip.

b) Add the user to the sudo group

You now have a sudo user called newuser.

Step 1: Install OpenJDK

To install Tomcat 9 you will need Java Standard Edition (SE) 8 or higher to be installed. Achieve this by installing OpenJDK, an open-source implementation of Java SE and Java Development Kit (JDK).

First, you will need to update our apt package:

Then next:

At the time of this writing, OpenJDK14 is the latest version of OpenJDK. After the installation is complete, verify it by checking your java version as below:

Step 2: Create a Tomcat User

You can use Tomcat as a root user but this poses a serious security threat. Therefore, you’ll need to create a new user that will run the service with a home directory of /opt/tomcat. This directory is where you will install Tomcat, created with a shell of /bin/false so that no one can log into it.

Run the command below to do this:

Step 3: Install Tomcat

The official binary distribution of Tomcat can be obtained from the Tomcat download page.

You can use the wget command to download the Tomcat zip file to the /tmp directory, a temporary folder location.

If you have issues with using wget, you can optionally use the curl command to download Tomcat. First, download curl:

Then use curl with the link you got from the Tomcat website:

NOTE: If you used wget, there’s no need to use curl as well. They both achieve the same the same goal.

When the download is complete extract the archive to the /opt/tomcat directory:

Tomcat gets regular updates with security fixes and patches. To ensure that you have more control over these updates, create a symbolic link called latest which points to the installation directory.

When you get an update, all you’ll have to do is unpack your download and make the symbolic link point to it.

Next, update permissions. The command below gives permission to the Tomcat user and group:

You need to make the shell scripts in Tomcat’s bin directory executable:

Step 4: Create a Unit File

You will need to run Tomcat as a service instead of using shell scripts. This requires a systemd unit file in the /etc/systemd/system/ directory:

Now paste the configuration below.

Save and close the file. Then reload systemctl to ensure that the new changes are acknowledged by the system:

Now start the Tomcat service:

Check if the application has started without any errors:

The above output confirms that the Tomcat server is up and running.

You can always manage your Tomcat service just like any other systemd service:

Step 5: Configure Firewall Settings

You may need to access your server out of your local network. To achieve this, adjust your firewall settings and open port 8080.

After modifying the firewall permissions, you can now access the default Tomcat page by going to your-ip-address:8080 in your web browser. Don’t click the link for your Manager App at this stage, as you will be denied access (you can configure that later).

If you wish to have Tomcat service automatically start at boot time, use:

Step 6: Configure Management Interface

At this point, the web management interface is inaccessible because you haven’t yet defined Tomcat users and their roles. The tomcat-users.xml is the descriptor file. Open it in your terminal as below:

When the file opens, you will see default text which contains comments and examples.

Add the following code at the bottom, just above .

The new user will now have access to the web interface (manager-gui and admin-gui). Ensure that you change the password to something more secure.

Step 7: Test the Installation

First, restart your application:

Then in your browser, type localhost:8080. Once you get the page below, then you will know that the installation was successful.

The Tomcat application manager dashboard can be reached at http://localhost:8080/manager/html. From here, you can start managing (start, stop, reload, deploy and undeploy) your applications.

The virtual host manager dashboard can be reached at http://localhost:8080/host-manager/html. You can manage you Tomcat virtual hosts from here.

The Tomcat Is Ready to Run

Now that your installation is complete, you can deploy a Java application and begin playing around with JSPs (Java Server Pages), servlets, and more.

At this point, your Tomcat data is entirely unencrypted. Your sensitive data like passwords are sent in plain text and can be viewed by unwanted parties. To protect yourself, you can encrypt your connections with SSL.

You can also visit the official Apache Tomcat documentation to know more about Tomcat’s features. If you find it difficult to follow through, you can always seek help from the vibrant developer communities online, like Stack Overflow.