Install Tomcat on Linux
Deploying Java-based web applications requires a robust, efficient servlet container. Apache Tomcat remains one of the world's most popular open-source solutions for executing Java Servlets, JavaServer Pages (JSP), and WebSockets code definitions. In this step-by-step infrastructure guide, we will walk through how to configure a production-ready baseline installation of Tomcat 9.0.21 on a Linux runtime environment.
Step 1: Installing JDK (Java Development Kit)
Because Apache Tomcat is written completely in Java, it relies on an underlying runtime engine. Tomcat 9 requires Java SE 8 or later variants installed on the host system. Let's first ensure a viable runtime engine environment exists by auditing standard versions.
Check your current Java version details using the following command terminal hook:
$ java -version
If the shell execution returns a command missing error, update the local package architecture indices and apply the default system-wide Java Development Kit package:
$ sudo apt-get update
$ sudo apt-get install default-jdk -y
Once configuration scripts terminate successfully, run the diagnostics pass once again to verify the compiler parameters:
$ java -version
Step 2: Creating a Dedicated Tomcat User and Group
Running service utilities under a standard privileged administrative account introduces massive security holes into production servers. To isolate your application environment, provision a sandboxed group and an unprivileged service daemon user constrained from systemic layout access.
Create a tracking group array followed immediately by a system service user assignment targeting non-interactive environments:
$ sudo groupadd tomcat
$ sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Step 3: Download and Extract Tomcat 9
With the runtime identity sandboxed, pull down the distribution tarball mirror archive structures directly into the targeted host mount layouts.
Navigate toward the global standard /opt storage path structure and initialize a secure transfer
download using the command utility framework:
$ cd /opt
$ sudo wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.21/bin/apache-tomcat-9.0.21.tar.gz
Extract the compressed bin assets package structure into active paths, then remap the directory layout cleanly to conform with your user home configuration setups:
$ sudo tar -xvzf apache-tomcat-9.0.21.tar.gz
$ sudo mv apache-tomcat-9.0.21 /opt/tomcat
Step 4: Set Up Path Variables and Boot Tomcat
To execute internal management scripts cleanly from terminal wrappers without assigning persistent system flags, append tactical context assignments temporarily.
Shift directories over into the binary executable container path array:
$ cd /opt/tomcat/bin
Export your active context location variables temporarily into the current running terminal path hook:
$ export PATH=$PATH:$(pwd)
Initialize the underlying structural Catalina process listener system thread loops by launching the startup wrapper:
$ ./catalina.sh start
Your Tomcat server instance should now be running successfully and listening on port 8080.
Written by A.M. Rinas