Step-by-Step Guide: Install Tomcat on a Linux System
Step 1: Preparations
Before installing Apache Tomcat, ensure that Java is installed on your system. The latest Long-Term Support (LTS) version is OpenJDK 21, released in September 2023.
Update your package sources:
sudo apt update
Install the default JDK:
sudo apt install default-jdk
Verify the Java installation:
java -version
Step 2: Set Up Tomcat User
It’s recommended to run Tomcat under a dedicated user. Create a new user named ‘tomcat’:
sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat
Step 3: Download Tomcat Package
As of January 2025, the latest stable version of Apache Tomcat is 10.1.x. APACHE TOMCAT
Download the latest version:
wget https://downloads.apache.org/tomcat/tomcat-10/v10.1.34/bin/apache-tomcat-10.1.34.tar.gz
Step 4: Install Tomcat on Linux
Extract the downloaded archive to /opt/tomcat:
sudo mkdir /opt/tomcat
sudo tar xf apache-tomcat-10.1.34.tar.gz -C /opt/tomcat --strip-components=1
Adjust permissions:
sudo chown -R tomcat: /opt/tomcat
sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh'
Step 5: Configure Tomcat Service
Create a systemd service file for Tomcat:
sudo nano /etc/systemd/system/tomcat.service
Add the following content:
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
Environment=”JAVA_HOME=/usr/lib/jvm/java-1.21.0-openjdk-amd64″
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
Reload the systemd daemon:
sudo systemctl daemon-reload
Start and enable the Tomcat service:
sudo systemctl start tomcat
sudo systemctl enable tomcat
Step 6: Allow Port 8080
If you have a firewall enabled, allow traffic on port 8080:
sudo ufw allow 8080/tcp
Step 7: Verify Installation
Open your web browser and navigate to http://<your_server_ip>:8080. You should see the Apache Tomcat homepage.
Conclusion
By following these steps, you’ve successfully installed Apache Tomcat 10.1.x on your Linux system. This setup allows you to deploy Java Servlets and JSPs efficiently. For more information and updates, visit the official Apache Tomcat website.