How to Install Apache Tomcat 9 on Ubuntu 18.04

Dịch vụ Hosting Vps giá rẻ

VPS Việt Nam giá rẻ, cấu hình mạnh, ổn định. Được đặt tại Datacenter FPT. Giá chỉ từ 50k cùng nhiều phần quà hấp dẫn Nâng cấp dễ dàng, không tốn thêm phí Cam kết hoàn tiền ngay nếu không hài lòng . Đăng Ký : vps giá rẻ Ngay.
Follow Me

Apache Tomcat is an accessible, open-source application server used to house many of today applications. It’s free, stable, lightweight and is utilized to render Java coding as well a range of other applications.

Today we will be focusing on how to install Apache Tomcat 9 on our Liquid Web Ubuntu server, specifically Ubuntu 18.04 LTS.

  • Open the terminal and log in as root. If you are logged in as another user, you will need to add sudo before each command.
  • Working on a Linux Ubuntu 18.04 server

Step 1: Install or Verify Java 8 is installed

java -version

If nothing is returned or you get the message “No such file or directory” then you’ll need to install Java 8.

In this case, we’ll be installing OpenJDK 8 because it’s free and, the OracleJDK recently reached its EOL in January 2019.

apt install default-jdk -y


If Java was installed successfully, you’d see something like this when using the java -version command

java -version


openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)


Step 2: Install Tomcat 9



Step 3: Extract Tomcat 9 Tarball

However, fun to think about, this tarball doesn’t belong to any cat, it belongs to Tomcat!

We’ll be moving this tarball into the /opt/tomcat directory.

mkdir /opt/tomcat

mv apache-tomcat-9.0.8.tar.gz /opt/tomcat

tar -xvzf /opt/tomcat/apache-tomcat-9.0.8.tar.gz


Step 4: Create a Tomcat user

We create the tomcat user as extra security as this user will be the one who has group ownership to the Tomcat files.

groupadd tomcat

useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat


Step 5: Update permissions to Tomcat

Since Tomcat belongs to the group category, we have to update the permission for some of the directories of Tomcat.

chgrp -R tomcat /opt/tomcat

cd /opt/tomcat/apache-tomcat-9.0.8

chmod -R g+r conf

chmod g+x conf

chown -R tomcat webapps/ work/ temp/ logs/


Step 6: Create a Systemd Service File

Copy the path of Tomcat’s home by running this command:

update-java-alternatives -l

java-1.11.0-openjdk-amd64      1101       /usr/lib/jvm/java-1.11.0-openjdk-amd64</b


Your path may look different but, that’s alright, take the highlighted path and put it into your /etc/systemd/system/tomcat.service file, as the JAVA_HOME variable (shown below).

vim /etc/systemd/system/tomcat.service

Just as the path may look different from our example, you’ll focus on providing the variables in this file the path to our Tomcat installation(a.k.a. Tomcat’s root directory). For example, we’ll let the server know that the and files are located in the /bin directory of Tomcat. At any rate, be sure that your paths (bolded in the example) are the correct paths.


[Unit] Description=Apache Tomcat
[Service] Type=forking
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'

Be sure to save the file by using :wq


Step 7: Reload the Systemd File

We do this so the system can recognize the changes to the file that we just edited.

systemctl daemon-reload


Step 8: Restart Tomcat

systemctl start tomcat

If the Tomcat service fails to start use journalctl -xn as a way to know the exact errors that are occurring.


Step 9: Verify Tomcat is Running

systemctl status tomcat


* tomcat.service - Apache Tomcat
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-04-04 14:33:04 EDT; 4min 29s ago
Process: 10912 ExecStart=/opt/tomcat/apache-tomcat-9.0.8/bin/ (code=exited, status=0/SUCCESS)
Main PID: 10930 (java)
Tasks: 47 (limit: 2157)
CGroup: /system.slice/tomcat.service
`-10930 /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomcat/apache-tomcat-9.0.8/conf/ -Djava.util.logging.manage

If correctly installed you’ll also be able to see the Tomcat default page by visiting http://Host_IP:8080 in your browser, replacing Host_IP with your server’s IP or hostname, followed by Tomcat’s port number 8080.