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 updateInstall the default JDK:
sudo apt install default-jdkVerify the Java installation:
java -versionMatching infrastructure at centron
No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →
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 tomcatStep 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.gzStep 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=1Adjust 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.serviceAdd 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-reloadStart and enable the Tomcat service:
sudo systemctl start tomcat
sudo systemctl enable tomcatStep 6: Allow Port 8080
If you have a firewall enabled, allow traffic on port 8080:
sudo ufw allow 8080/tcpStep 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.
Testen Sie Ihr Setup auf ccloud³
Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.