How to Install Tomcat 10 on Ubuntu 22.04
Tomcat is a popular open-source Java Servlet Container that can be used to run Java applications. In this article, we will explain how to install Tomcat 10 on Ubuntu 22.04. This guide assumes that you have a fresh installation of Ubuntu 22.04 and that you are logged in as a non-root user with sudo privileges. If you do not have sudo privileges, you can install Tomcat using the root user, but this is not recommended for security reasons.
Prerequisites
Before we begin, we need to make sure that your system meets the following requirements:
- Ubuntu 22.04 installed on your system
- A non-root user with sudo privileges
- Java installed on your system. You can check if Java is installed by running the following command in the terminal:
java -version
If Java is not installed, you can install it by running the following command:
sudo apt update
sudo apt install openjdk-11-jdk
Downloading Tomcat 10
The first step in installing Tomcat 10 on Ubuntu 22.04 is to download the latest version of Tomcat. You can download Tomcat from the official website at http://tomcat.apache.org. At the time of writing this article, the latest version of Tomcat is 10.0.6. You can download the latest version of Tomcat by running the following command in the terminal:
wget http://mirrors.estointernet.in/apache/tomcat/tomcat-10/v10.0.6/bin/apache-tomcat-10.0.6.tar.gz
Extracting the Tomcat Package
Once the download is complete, extract the Tomcat package by running the following command:
tar -xf apache-tomcat-10.0.6.tar.gz
This will extract the Tomcat package to a directory named “apache-tomcat-10.0.6”. You can move this directory to any location on your system. In this guide, we will move it to the “/opt” directory by running the following command:
sudo mv apache-tomcat-10.0.6 /opt/
Creating a Tomcat User
It is recommended to run Tomcat as a non-root user for security reasons. In this section, we will create a new user named “tomcat”. You can create the “tomcat” user by running the following command in the terminal:
sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat
Setting the Ownership of Tomcat Files
Now that we have created the “tom
cat” user, we need to set the ownership of the Tomcat files to the “tomcat” user. This can be done by running the following command:
sudo chown -R tomcat:tomcat /opt/tomcat
Configuring Systemd Unit File for Tomcat
In this section, we will create a Systemd unit file for Tomcat. This will allow us to manage the Tomcat service using Systemd commands. To create the Systemd unit file, run the following command:
sudo nano /etc/systemd/system/tomcat.service
This will open the nano text editor. Paste the following content in the editor and save the file:
[Unit] Description=Apache Tomcat Web Application Container After=network.target [Service] Type=forking User=tomcat Group=tomcat Environment=JAVA_HOME=/usr/lib/jvm/java-11-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 [Install] WantedBy=multi-user.target
In the above file, we have specified the environment variables for Tomcat. We have also specified the start and stop scripts for the Tomcat service. Save the file and exit the nano text editor.
Reloading Systemd Daemon
After creating the Systemd unit file, we need to reload the Systemd daemon to pick up the changes. This can be done by running the following command:
sudo systemctl daemon-reload
Starting the Tomcat Service
We are now ready to start the Tomcat service. You can start the Tomcat service by running the following command:
sudo systemctl start tomcat
You can check the status of the Tomcat service by running the following command:
sudo systemctl status tomcat
If the Tomcat service is running, you should see the following output:
● tomcat.service - Apache Tomcat Web Application Container Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled) Active: active (running) since Wed 2022-12-21 12:34:56 UTC; 1h 33min ago Main PID: 14064 (java) Tasks: 55 (limit: 4915) CGroup: /system.slice/tomcat. service └─14064 /usr/lib/jvm/java-11-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dcatalina.base=/opt/tomcat -Dcatalina.home=/opt/tomcat -Djava.io.tmpdir=/opt/tomcat/temp -Xms512M -Xmx1024M -server -XX:+UseParallelGC -Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -jar /opt/tomcat/bin/bootstrap.jar start
Enabling the Tomcat Service
If you want the Tomcat service to start automatically at boot time, you can enable the service by running the following command:
sudo systemctl enable tomcat
Accessing the Tomcat Web Management Interface
Now that the Tomcat service is running, you can access the Tomcat web management interface by opening your web browser and navigating to the following URL:
http://your-server-ip:8080
Replace “your-server-ip” with the IP address of your Ubuntu 22.04 server. You should see the Tomcat default landing page, which confirms that Tomcat is installed and running on your server.
Securing Tomcat
By default, the Tomcat web management interface is open to the public, which can pose a security risk. To secure your Tomcat installation, you can do the following:
- Change the default Tomcat administrator username and password.
- Limit access to the Tomcat web management interface to specific IP addresses or networks.
- Use SSL encryption to secure the communication between the client and the server.
These security measures can be implemented by editing the Tomcat configuration files. For more information on securing your Tomcat installation, you can refer to the Tomcat official documentation.
Conclusion
In this article, we have learned how to install Tomcat 10 on Ubuntu 22.04. We have covered all the necessary steps, from downloading the Tomcat distribution to configuring the Systemd unit file for Tomcat. By following this guide, you should now have a working Tomcat installation on your Ubuntu 22.04 server. If you have any questions or need further assistance, feel free to leave a comment below.