Install Tomcat 9 on Ubuntu 16.04

Install Tomcat 9 on Ubuntu 16.04
We’ll show you, how to install Tomcat 9 on Ubuntu 16.04. Apache Tomcat (previously known as Jakarta Tomcat) or simply Tomcat, is an open source web server and servlet container developed by the Apache Software Foundation. It executes Java servlets and renders Web pages that include Java Server Page coding and it is one of the most popular web servers used by the java developers. In this article we will install the latest release of Tomcat 9 server on an Ubuntu 16.04 VPS. This tutorial should work on other Debian based systems as well but was tested and written for Ubuntu 16.04

1. Login via SSH

First of all login to your Ubuntu 16.04 VPS via SSH as user root

ssh root@IP_address

2. Start a new screen session

screen -U -S tomcat9

3. Update All System Packages

To update all packages installed on your server run the following command in the terminal

apt-get update && apt-get upgrade

4. Install Java

In order to run Tomcat server, Java has to be installed on the VPS. Execute the following command to install the Java Development Kit package (JDK)

apt-get install default-jdk

After the installation is completed, You can check the Java installed on your server using the command below

java -version

If you receive an output similar to the one above, the installation is successful.

openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Once Java is installed on the server, we will proceed installing Tomcat 9.

5. Install and Configure Tomcat 9

For security reasons it is not recommended to run Tomcat as user root, so we will create a new system user

useradd -r tomcat9 --shell /bin/false

Change the current working directory to /opt and download the latest Tomcat 9 release to the /opt directory on your server. At the moment of writing this tutorial Tomcat version 9.0.0.M6 is the latest one. You should go to Tomcat’s official website and check if a newer version is available.

cd /opt
wget http://mirror.symnds.com/software/Apache/tomcat/tomcat-9/v9.0.0.M9/bin/apache-tomcat-9.0.0.M9.tar.gz

Extract the content of the ‘apache-tomcat-9.0.0.M6.tar.gz’ tarball archive

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
tar -zxf apache-tomcat-9.0.0.M6.tar.gz

Create a symbolic link of the Tomcat directory to /opt/tomcat-latest and set the appropriate ownership:

ln -s apache-tomcat-9.0.0.M6 tomcat-latest
chown -hR tomcat9: tomcat-latest apache-tomcat-9.0.0.M6

Tomcat can be started, stopped and restarted using the bash scripts located in the /opt/tomcat-latest/bin directory or even better, we will create a systemd init file for that purpose

nano /etc/systemd/system/tomcat.service

and add the following content to the file

[Unit]
Description=Tomcat9
After=network.target

[Service]
Type=forking
User=tomcat9
Group=tomcat9

Environment=CATALINA_PID=/opt/tomcat-latest/tomcat9.pid
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
Environment=CATALINA_HOME=/opt/tomcat-latest
Environment=CATALINA_BASE=/opt/tomcat-latest
Environment="CATALINA_OPTS=-Xms512m -Xmx512m"
Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC"

ExecStart=/opt/tomcat-latest/bin/startup.sh
ExecStop=/opt/tomcat-latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

Save the file, reload the systemd daemon, start the Tomcat server and enable it to start on boot

systemctl daemon-reload
systemctl start tomcat
systemctl enable tomcat

Finally, if you closely followed the instructions in this tutorial you will be able to access Tomcat by navigating your favorite web browser to http://your_server_IP:8080

Of course you don’t have to install Tomcat 9 on Ubuntu 16.04 if you use one of our SSD VPS Hosting services, in which case you can simply ask our expert Linux admins to install Tomcat 9 for you. They are available 24×7 and will take care of your request immediately. You can also read our guide on How to Install Tomcat on Ubuntu 18.04.

PS. If you liked this post, on how to install Tomcat 9 on Ubuntu 16.04, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

1 thought on “Install Tomcat 9 on Ubuntu 16.04”

Leave a Comment