How to Install Apache Tomcat 9.0.21 on Ubuntu 19.04

Installation of Apache Tomcat 9.0.21

Pre-requisistes:

Java

Download link :

enter link description here

Installation procedure:

Update the apt repository to bring the pre-installed packages up to date

root@linuxhelp:~# apt update
Hit:1 http://ppa.launchpad.net/linuxuprising/java/ubuntu disco InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu disco InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu disco-updates InRelease
Hit:4 http://security.ubuntu.com/ubuntu disco-security InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu disco-backports InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
172 packages can be upgraded. Run 'apt list --upgradable' to see them.

Change the directory to /usr/local

root@linuxhelp:~# cd /usr/local

Download the apache tomcat 9.0.21 version usning wget followed by the mentioned downloaded link

root@linuxhelp:/usr/local# wget  http://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.21/bin/apache-tomcat-9.0.21.zip
--2019-06-18 14:45:29--  http://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.21/bin/apache-tomcat-9.0.21.zip
Resolving mirrors.estointernet.in (mirrors.estointernet.in)... 103.123.234.254, 2403:8940:ffff::f
Connecting to mirrors.estointernet.in (mirrors.estointernet.in)|103.123.234.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11478988 (11M) [application/zip]
Saving to: ‘apache-tomcat-9.0.21.zip’

apache-tomcat-9.0.21.zip      100%[==============================================>]  10.95M   305KB/s    in 15s     

2019-06-18 14:45:44 (768 KB/s) - ‘apache-tomcat-9.0.21.zip’ saved [11478988/11478988]

List the contents to view the zip file of apache tomcat 9.0.21

root@linuxhelp:/usr/local# ll
total 11252
drwxr-xr-x 10 root root     4096 Jun 18 14:45 ./
drwxr-xr-x 14 root root     4096 Apr 17 00:30 ../
-rw-r--r--  1 root root 11478988 Jun  5 02:18 apache-tomcat-9.0.21.zip
drwxr-xr-x  2 root root     4096 Apr 17 00:29 bin/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 etc/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 games/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 include/
drwxr-xr-x  3 root root     4096 Apr 17 00:29 lib/
lrwxrwxrwx  1 root root        9 Apr 26 14:08 man -> share/man/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 sbin/
drwxr-xr-x  5 root root     4096 Apr 17 00:33 share/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 src/

Extract the zip file of apache tomcat

root@linuxhelp:/usr/local# unzip apache-tomcat-9.0.21.zip
Archive:  apache-tomcat-9.0.21.zip
   creating: apache-tomcat-9.0.21/
   creating: apache-tomcat-9.0.21/bin/
   creating: apache-tomcat-9.0.21/conf/
   creating: apache-tomcat-9.0.21/lib/
   creating: apache-tomcat-9.0.21/logs/
   creating: apache-tomcat-9.0.21/temp/
   creating: apache-tomcat-9.0.21/webapps/
   creating: apache-tomcat-9.0.21/webapps/ROOT/
   creating: apache-tomcat-9.0.21/webapps/ROOT/WEB-INF/
   creating: apache-tomcat-9.0.21/webapps/docs/
   creating: apache-tomcat-9.0.21/webapps/docs/WEB-INF/
   creating: apache-tomcat-9.0.21/webapps/docs/api/
   creating: apache-tomcat-9.0.21/webapps/docs/appdev/
   creating: apache-tomcat-9.0.21/webapps/docs/appdev/sample/
   creating: apache-tomcat-9.0.21/webapps/docs/appdev/sample/docs/
   creating: apache-tomcat-9.0.21/webapps/docs/appdev/sample/src/
.
.
.
.
.
.
.
.
inflating: apache-tomcat-9.0.21/webapps/manager/images/asf-logo.svg  
  inflating: apache-tomcat-9.0.21/webapps/manager/images/tomcat.gif  
  inflating: apache-tomcat-9.0.21/webapps/manager/index.jsp  
  inflating: apache-tomcat-9.0.21/webapps/manager/status.xsd  
  inflating: apache-tomcat-9.0.21/webapps/manager/xform.xsl  

View the extracted directory by listing the contents

root@linuxhelp:/usr/local# ll
total 11256
drwxr-xr-x 11 root root     4096 Jun 18 14:46 ./
drwxr-xr-x 14 root root     4096 Apr 17 00:30 ../
drwxr-xr-x  9 root root     4096 Jun  4 21:23 apache-tomcat-9.0.21/
-rw-r--r--  1 root root 11478988 Jun  5 02:18 apache-tomcat-9.0.21.zip
drwxr-xr-x  2 root root     4096 Apr 17 00:29 bin/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 etc/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 games/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 include/
drwxr-xr-x  3 root root     4096 Apr 17 00:29 lib/
lrwxrwxrwx  1 root root        9 Apr 26 14:08 man -> share/man/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 sbin/
drwxr-xr-x  5 root root     4096 Apr 17 00:33 share/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 src/

Rename the extracted directory

root@linuxhelp:/usr/local# mv apache-tomcat-9.0.21 tomcat9

View the renamed directory by listing the contents

root@linuxhelp:/usr/local# ll
total 11256
drwxr-xr-x 11 root root     4096 Jun 18 14:46 ./
drwxr-xr-x 14 root root     4096 Apr 17 00:30 ../
-rw-r--r--  1 root root 11478988 Jun  5 02:18 apache-tomcat-9.0.21.zip
drwxr-xr-x  2 root root     4096 Apr 17 00:29 bin/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 etc/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 games/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 include/
drwxr-xr-x  3 root root     4096 Apr 17 00:29 lib/
lrwxrwxrwx  1 root root        9 Apr 26 14:08 man -> share/man/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 sbin/
drwxr-xr-x  5 root root     4096 Apr 17 00:33 share/
drwxr-xr-x  2 root root     4096 Apr 17 00:29 src/
drwxr-xr-x  9 root root     4096 Jun  4 21:23 tomcat9/

Change the directory to tomcat9 and bin as well

root@linuxhelp:/usr/local# cd tomcat9/
root@linuxhelp:/usr/local/tomcat9# cd bin

Configure the environment variable for apache tomcat 9.0.21

root@linuxhelp:/usr/local/tomcat9/bin# echo "export CATALINA_HOME="/usr/local/tomcat9"" >> ~/.bashrc

Reload the environment file

root@linuxhelp:/usr/local/tomcat9/bin# source ~/.bashrc

List the contents in the bin directory

root@linuxhelp:/usr/local/tomcat9/bin# ll
total 872
drwxr-xr-x 2 root root   4096 Jun  4 21:21 ./
drwxr-xr-x 9 root root   4096 Jun  4 21:23 ../
-rw-r--r-- 1 root root  35064 Jun  4 21:21 bootstrap.jar
-rw-r--r-- 1 root root  15900 Jun  4 21:21 catalina.bat
-rw-r--r-- 1 root root  23447 Jun  4 21:21 catalina.sh
-rw-r--r-- 1 root root   1703 Jun  4 21:21 catalina-tasks.xml
-rw-r--r-- 1 root root   2123 Jun  4 21:21 ciphers.bat
-rw-r--r-- 1 root root   1997 Jun  4 21:21 ciphers.sh
-rw-r--r-- 1 root root  25145 Jun  4 21:21 commons-daemon.jar
-rw-r--r-- 1 root root 207125 Jun  4 21:21 commons-daemon-native.tar.gz
-rw-r--r-- 1 root root   2040 Jun  4 21:21 configtest.bat
-rw-r--r-- 1 root root   1922 Jun  4 21:21 configtest.sh
-rw-r--r-- 1 root root   8513 Jun  4 21:21 daemon.sh
-rw-r--r-- 1 root root   2091 Jun  4 21:21 digest.bat
-rw-r--r-- 1 root root   1965 Jun  4 21:21 digest.sh
-rw-r--r-- 1 root root   3606 Jun  4 21:21 makebase.bat
-rw-r--r-- 1 root root   3382 Jun  4 21:21 makebase.sh
-rw-r--r-- 1 root root   3460 Jun  4 21:21 setclasspath.bat
-rw-r--r-- 1 root root   3708 Jun  4 21:21 setclasspath.sh
-rw-r--r-- 1 root root   2020 Jun  4 21:21 shutdown.bat
-rw-r--r-- 1 root root   1902 Jun  4 21:21 shutdown.sh
-rw-r--r-- 1 root root   2022 Jun  4 21:21 startup.bat
-rw-r--r-- 1 root root   1904 Jun  4 21:21 startup.sh
-rw-r--r-- 1 root root  47880 Jun  4 21:21 tomcat-juli.jar
-rw-r--r-- 1 root root 418909 Jun  4 21:21 tomcat-native.tar.gz
-rw-r--r-- 1 root root   4574 Jun  4 21:21 tool-wrapper.bat
-rw-r--r-- 1 root root   5515 Jun  4 21:21 tool-wrapper.sh
-rw-r--r-- 1 root root   2026 Jun  4 21:21 version.bat
-rw-r--r-- 1 root root   1908 Jun  4 21:21 version.sh

Assign executable permissions to both startup.sh and catalina.sh

root@linuxhelp:/usr/local/tomcat9/bin# chmod a+x catalina.sh
root@linuxhelp:/usr/local/tomcat9/bin# chmod a+x startup.sh

Now,run the startup.sh script to start the tomcat

root@linuxhelp:/usr/local/tomcat9/bin# ./startup.sh
Using CATALINA_BASE:   /usr/local/tomcat9
Using CATALINA_HOME:   /usr/local/tomcat9
Using CATALINA_TMPDIR: /usr/local/tomcat9/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat9/bin/bootstrap.jar:/usr/local/tomcat9/bin/tomcat-juli.jar
Tomcat started.

Verify the tomcat port number usning netstat

root@linuxhelp:/usr/local/tomcat9/bin# netstat -tulpn | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      36276/java          

Check the version of java

root@linuxhelp:/usr/local/tomcat9/bin# java -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)

Open the browser and enter the machine’s IP followed by the tomcat’s port number to view the test page of Apache tomcat 9.0.21 version

With this,installation of Apache Tomcat 9.0.21 version On ubuntu 19.04 comes to end here.

FAQ
Q
What does source ~/.bashrc do in apache tocmat 9.0.21?
A
bashrc is the configuration file of bash whereas ~/.bashrc is a home folder of a current logged-in user .In source ~/.bashrc,Source command just executes the home folder of a current working user which reloads the file.
Q
Why is java essential for Apache tomcat 9.0.21?
A
Apache tomcat is a java servlet container which runs on a Java virtual machine ,So java is essential for apache tomcat 9.0.21
Q
What does startup.sh do in apache tomcat 9.0.21?
A
Startup script simply runs catalina with the start argument in apache tomcat 9.0.21
Q
What is catalina.sh script in apache tomcat 9.0.21?
A
catalina.sh is the script that is actually responsible for starting apache tomcat 9.0.21.
Q
What is the use of /usr/local directory in apache tomcat 9?
A
The use of /usr/local directory in apache tomcat 9 is for storing third-party programs where programs and data can be sharable amongst a group of hosts and locally installed software should be placed inside this directory.