How to install Tomcat9 on Ubuntu 17.04

To install Tomcat9 on Ubuntu 17.04

Apache 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. It is really so simple to install Apache Tomcat on Ubuntu 17.04, and this article covers the ground on the same process. 


Installing Tomcat9 

In order to install Tomcat, it is really very essential to install Java, so make sure you run the following command. 

root@linuxhelp11:~# apt-get install default-jdk
Reading package lists... Done
Building dependency tree       
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
  libgif7 libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libx11-doc
  libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-8-jdk
  openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
  x11proto-core-dev x11proto-input-dev x11proto-kb-dev xorg-sgml-doctools
Suggested packages:.
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...


Once it is done, you can check if its installed properly by making use of the following command which displays the version of Java. 

root@linuxhelp11:~# java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.17.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)


After that, you should create a  user for Tomcat. 

root@linuxhelp11:~# useradd -r tomcat9 --shell /bin/false


And then, you need to enter into opt location and for that, you need to run the following command. 

root@linuxhelp11:~# cd /opt


Now, you shall download tomcat9 package by using the wget command in the following manner. 

root@linuxhelp11:/opt#  wget
--2017-11-24 05:35:47--
Resolving (
Connecting to (||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9397803 (9.0M) [application/x-gzip]
Saving to: ‘apache-tomcat-9.0.1.tar.gz’
apache-tomcat-9.0.1 100%[===================>]   8.96M  11.3MB/s    in 0.8s    
2017-11-24 05:36:05 (11.3 MB/s) - ‘apache-tomcat-9.0.1.tar.gz’ saved [9397803/9397803]


After that, make sure you extract the downloaded file by using the following command. 

root@linuxhelp11:/opt# tar -zxf apache-tomcat-9.0.1.tar.gz


You should also create the symbolic link for extracted directory by making use of the following command. 

root@linuxhelp11:/opt# ln -s apache-tomcat-9.0.1 tomcat-latest


And then, you should change the ownership of the extracted directory by running the following command. 

root@linuxhelp11:/opt# chown -hR tomcat9: tomcat-latest apache-tomcat-9.0.1


Next, you should create user for manager and admin in tomcat-user file as follows. 

root@linuxhelp11:/opt# vim tomcat-latest/conf/tomcat-users.xml
And in that file, add the following. 
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="admin" password="password" roles="manager-gui,admin-gui"/>

Next, make an entry to allow the server 

root@linuxhelp11:/opt# vim tomcat-latest/webapps/manager/META-INF/context.xml
in file , modify following
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1|< server ip >" />

root@linuxhelp11:/opt# vim tomcat-latest/webapps/host-manager/META-INF/context.xml
in file , modify following
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1|< server ip >" />

configure deomon file for start and stop tomcat service

root@linuxhelp11:/opt# vim /etc/systemd/system/tomcat.service
in file , add following
Environment="CATALINA_OPTS=-Xms512m -Xmx512m"
Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC"

And then, reload deomon with the help of the following commamd. 

root@linuxhelp11:/opt# systemctl daemon-reload


You shall now start the Tomcat service by running the following command.  

root@linuxhelp11:/opt# systemctl start tomcat


Also, you need to enable the Tomcat service through the following command. 

root@linuxhelp11:/opt# systemctl enable tomcat

Created symlink from /etc/systemd/system/ to /etc/systemd/system/tomcat.service.

Now, open your browser and give localhost:8080 as the URL . The home page of Tomcat appears on your screen. 


If you want to open the manager app, then click on it. 


And give your login credentials in the popup that appears. 



The Manager page of Tomcat now appears. 

Tomcat 1


If you want to open the VirtualHost for admin panel, then click on Host manage.



In the popup that appears, give your credentials.



The Host page now appears. 



With this, the installation of Tomcat9 comes to an end. 

Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Ubuntu Tomcat
user image Author :  Gabriel