This article will take you through how to install Apache Tomcat on Ubuntu 22.04. Apache Tomcat software is an open-source implementation of the Jakarta Servlet, Jakarta Server Pages, Jakarta Expression Language, Jakarta WebSocket, Jakarta Annotations and Jakarta Authentication specifications.
How to Install Apache Tomcat on Ubuntu 22.04
- Update your packages using the command below.
sudo apt update
- Install Java on your system.
sudo apt install default-jdk
Sample output
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: ca-certificates-java default-jdk-headless default-jre default-jre-headless fonts-dejavu-extra java-common libatk-wrapper-java libatk-wrapper-java-jni libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless x11proto-dev xorg-sgml-doctools xtrans-dev Suggested packages: libice-doc libsm-doc libx11-doc libxcb-doc libxt-doc openjdk-11-demo openjdk-11-source visualvm fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei The following NEW packages will be installed: ca-certificates-java default-jdk default-jdk-headless default-jre default-jre-headless fonts-dejavu-extra java-common libatk-wrapper-java libatk-wrapper-java-jni libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless x11proto-dev xorg-sgml-doctools xtrans-dev 0 upgraded, 24 newly installed, 0 to remove and 4 not upgraded. Need to get 261 MB of archives. After this operation, 412 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 java-common all 0.72build2 [6,782 B]
Install Apache Tomcat
- Start by downloading Apache Tomcat, you can get the latest download link from the Apache Tomcat download page
sudo apt install wget
VER="10.0.23"
wget https://archive.apache.org/dist/tomcat/tomcat-10/v${VER}/bin/apache-tomcat-${VER}.tar.gz
- After downloading, extract it using the following command.
tar xvf apache-tomcat-${VER}.tar.gz
- Next, move the extracted files to the
/user
directory.
sudo mv apache-tomcat-${VER} /usr/share/apache-tomcat
- Then create an Apache Tomcat user using the following command.
sudo useradd -M -d /usr/share/apache-tomcat tomcat
- Give the user permission using the command below.
sudo chown -R tomcat /usr/share/apache-tomcat
- Next, allow one IP to access Apache Tomcat by adding it to the configuration file.
sudo nano /usr/share/apache-tomcat/webapps/manager/META-INF/context.xml
sudo nano /usr/share/apache-tomcat/webapps/host-manager/META-INF/context.xml
- In the above config files, add your IP address such as 192.168.5.30 as shown below.
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.5.30" />
- For Tomcat to be accessed by any IP address you have to remove the added IP.
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
Secure Apache Tomcat on Ubuntu 22.04
- Open the users’ configuration file using the command below.
sudo nano /usr/share/apache-tomcat/conf/tomcat-users.xml
Then above </tomcat-users>
add the configuration below. Note, replace YourStrongPassword with your real password.
Configure Systemd for Apache Tomcat
- Run the command below to create systemd file for Apache Tomcat.
sudo nano /etc/systemd/system/tomcat.service
Copy the content below and paste it into the file created above.
[Unit] Description=Tomcat After=syslog.target network.target [Service] Type=forking User=tomcat Group=tomcat Environment=JAVA_HOME=/usr/lib/jvm/default-java Environment='JAVA_OPTS=-Djava.awt.headless=true' Environment=CATALINA_HOME=/usr/share/apache-tomcat Environment=CATALINA_BASE=/usr/share/apache-tomcat Environment=CATALINA_PID=/usr/share/apache-tomcat/temp/tomcat.pid ExecStart=/usr/share/apache-tomcat/bin/catalina.sh start ExecStop=/usr/share/apache-tomcat/bin/catalina.sh stop [Install] WantedBy=multi-user.target
- Next, run the following command to reload systemd daemon.
sudo systemctl daemon-reload
- Then restart tomcat using the command below.
sudo systemctl restart tomcat
- Add tomcat on system boot applications.
sudo systemctl enable tomcat
- If you are using a firewall add Apache Tomcat
sudo ufw allow 8080
Access Apache Tomcat Web
- Open your web browser and enter your IP address followed by port 8080 e.g.
192.168.5.30:8080
- To login into your Manager dashboard, click on the Manager app as shown below and enter your username and password.
- Sample manager dashboard.
- That concludes our tutorial on how to install Apache Tomcat on Ubuntu 22.04.
Read more on Apache Tomcat Documentation
Other Tutorials
Install ClamAV on Rocky Linux 9