How to install Tomcat 9 on Debian 9 Stretch Linux


The objective is to install Tomcat 9 on Debian 9 Stretch Linux.

Operating System and Software Versions

  • Operating System: – Debian 9 Stretch
  • Software: – Oracle Java JDK 1.8.0_131, Tomcat 9.0.0.M21


Privileged access to your Debian system is required in order to perform Tomcat and Oracle Java installation.




  • # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ – requires given linux commands to be executed as a regular non-privileged user


Oracle Java JDK Installation

Tomcat’s prerequisite is Java JDK. Whether your install OpenJDK or Oracle’s JDK is up to you. This guide uses Oracle’s JDK, so let’s get java first out of our way. List all available Oracle JDK downloads using curl command. If curl is not yet available on your system you can install by # apt install curl:

$ curl -s | grep "otn-pub" | cut -d \" -f12

Copy the link for 64-bit Linux tarball and download it. Your download link will be different so update the below command with the download URL retrieved by previous command: Example:

$ curl -LOb "oraclelicense=a"

If all went well you should have Oracle Java JDK inside your current directory:

$ ls

Next step is to decompress the above tarball:

# mkdir /opt/java-jdk
# tar -C /opt/java-jdk -zxf jdk-8u131-linux-x64.tar.gz

Set Oracle Java JDK as default on your system. Update the below command where necessary:

# update-alternatives --install /usr/bin/java java /opt/java-jdk/jdk1.8.0_131/bin/java 1
# update-alternatives --install /usr/bin/javac javac /opt/java-jdk/jdk1.8.0_131/bin/javac 1

Oracle Java JDK should now be installed as default. Query java version to see if it is installed correctly:

# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Install Tomcat

At this stage java is installed and to continue with our Tomcat installation we need download Tomcat source tarball from the official tomcat website Download the latest Tomcat version using your browser or simply used wget or curl. Example:

$ wget

The Tomcat tarball should be now available within your current working directory:

$ ls 
apache-tomcat-9.0.0.M21.tar.gz  jdk-8u131-linux-x64.tar.gz

Next, create a dedicated user tomcat to run tomcat server:

# useradd -rs /bin/false tomcat

Extract Tomcat tarball:

# mkdir /opt/tomcat
# tar -C /opt/tomcat/ -zxf apache-tomcat-9.0.0.M21.tar.gz

The following step is optional, but highly recommended as it makes things much easier when updating tomcat with new version. Create a symbolic link pointing to latest tomcat directory:

# ln -s /opt/tomcat/apache-tomcat-9.0.0.M21/ /opt/tomcat/tomcat-latest

Make our previously created user tomcat an owner of the entire directories:

# chown -R tomcat.tomcat /opt/tomcat/tomcat-latest /opt/tomcat/apache-tomcat-9.0.0.M21

Note, when upgrading tomcat, simply unlink the current symbolic link and recreate new as shown in previous steps.

Next, create systemd startup script /etc/systemd/system/tomcat.service pointing to our new /opt/java-jdk and /opt/tomcat/tomcat-latest.

Below you can find the content of new /etc/systemd/system/tomcat.service systemd file:



Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m"

ExecStop=/bin/kill -15 $MAINPID


Lastly, reload systemd, start and enable tomcat to start after reboot:

# systemctl daemon-reload
# systemctl start tomcat
# systemctl enable tomcat

Access Tomcat

The last step is to confirm that Tomcat is up and running. Tomcat should be now listening on port 8080:

# ss -ant | grep 8080
LISTEN     0      100         :::8080

To access tomcat navigate your browser to an IP address of you new Tomcat server. Example

tomcat 9 on debian 9 stretch linux installation