This tutorial shows you how to install Tomcat on Ubuntu, with help of the buith-in apt-get
command.
1. apt-get install
1.1 Find an available Tomcat package to install
$ sudo apt-cache search tomcat
//...
tomcat7 - Servlet and JSP engine
tomcat7-admin - Servlet and JSP engine -- admin web applications
tomcat7-common - Servlet and JSP engine -- common files
tomcat7-docs - Servlet and JSP engine -- documentation
tomcat7-examples - Servlet and JSP engine -- example web applications
Updated on Ubuntu 20.04
$ sudo apt-cache search tomcat
[sudo] password for tvt:
resource-agents - Cluster Resource Agents
libapache-mod-jk-doc - Documentation of libapache2-mod-jk package
libapache2-mod-jk - Apache 2 connector for the Tomcat Java servlet engine
libjnlp-servlet-java - simple and convenient packaging format for JNLP applications
liblogback-java - flexible logging library for Java
liblogback-java-doc - flexible logging library for Java - documentation
libnetty-tcnative-java - Tomcat native fork for Netty
libnetty-tcnative-jni - Tomcat native fork for Netty (JNI library)
libsolr-java - Enterprise search server based on Lucene - Java libraries
libspring-instrument-java - modular Java/J2EE application framework - Instrumentation
libtcnative-1 - Tomcat native library using the Apache Portable Runtime
libtomcat9-embed-java - Apache Tomcat 9 - Servlet and JSP engine -- embed libraries
libtomcat9-java - Apache Tomcat 9 - Servlet and JSP engine -- core libraries
libtomcatjss-java - JSSE implementation using JSS for Tomcat
nagios-plugins-contrib - Plugins for nagios compatible monitoring systems
python3-ajpy - Python module to craft AJP requests
solr-common - Enterprise search server based on Lucene3 - common files
solr-jetty - Enterprise search server based on Lucene3 - Jetty integration
solr-tomcat - Enterprise search server based on Lucene3 - Tomcat integration
tomcat9 - Apache Tomcat 9 - Servlet and JSP engine
tomcat9-admin - Apache Tomcat 9 - Servlet and JSP engine -- admin web applications
tomcat9-common - Apache Tomcat 9 - Servlet and JSP engine -- common files
tomcat9-docs - Apache Tomcat 9 - Servlet and JSP engine -- documentation
tomcat9-examples - Apache Tomcat 9 - Servlet and JSP engine -- example web applications
tomcat9-user - Apache Tomcat 9 - Servlet and JSP engine -- tools to create user instances
yasat - simple stupid audit tool
1.2 Install the following Tomcat packages :
$ sudo apt-get install tomcat7
$ sudo apt-get install tomcat7-admin
Updated on Ubuntu 20.04, if we use apt so now we can install Tomcat 9 instead of Tomcat 7:
$ sudo apt-get install tomcat9
$ sudo apt-get install tomcat9-admin
1.3 Done. Tomcat is installed and configured automatically.
2. Where is Tomcat installed?
2.1 Tomcat auto start script is created in /etc/init.d/
folder.
$ sudo /etc/init.d/tomcat7 start
$ sudo /etc/init.d/tomcat7 stop
$ sudo /etc/init.d/tomcat7 restart
2.2 Tomcat bin folder is created in /usr/share/tomcat7
.
$ ls -lsa /usr/share/tomcat7/
4 drwxr-xr-x 4 root root 4096 Mac 11 23:21 .
12 drwxr-xr-x 282 root root 12288 Mac 11 23:21 ..
4 drwxr-xr-x 2 root root 4096 Mac 11 23:21 bin
4 -rw-r--r-- 1 root root 39 Jul 31 2013 defaults.md5sum
4 -rw-r--r-- 1 root root 2030 Jul 31 2013 defaults.template
4 drwxr-xr-x 2 root root 4096 Mac 11 23:21 lib
4 -rw-r--r-- 1 root root 53 Jul 31 2013 logrotate.md5sum
4 -rw-r--r-- 1 root root 118 Jul 31 2013 logrotate.template
2.3 Tomcat conf and logs folders are created in /var/lib/tomcat7
.
$ ls -lsa /var/lib/tomcat7/
4 drwxr-xr-x 6 root root 4096 Mac 11 23:21 .
4 drwxr-xr-x 64 root root 4096 Mac 11 23:21 ..
4 drwxr-xr-x 3 tomcat7 tomcat7 4096 Mac 11 23:21 common
0 lrwxrwxrwx 1 root root 12 Mac 5 01:20 conf -> /etc/tomcat7
0 lrwxrwxrwx 1 root root 17 Mac 5 01:20 logs -> ../../log/tomcat7
4 drwxr-xr-x 3 tomcat7 tomcat7 4096 Mac 11 23:21 server
4 drwxr-xr-x 3 tomcat7 tomcat7 4096 Mac 11 23:21 shared
4 drwxrwxr-x 3 tomcat7 tomcat7 4096 Mac 11 23:21 webapps
0 lrwxrwxrwx 1 root root 19 Mac 5 01:20 work -> ../../cache/tomcat7
3. Remove Tomcat installation
Follow this on the command line
sudo apt remove --purge tomcat7 tomcat7-admin tomcat7-docs
sudo apt autoremove
sudo apt autoclean
Use the above to purge any app from your system including config files.
Once this is complete you can use something like find or locate to remove any remaining stragglers.
sudo apt install locate && sudo updatedb
locate tomcat
And you can manually delete anything that might remain.
After removing the packages, you need to remove the tomcat directories too:
# rm –rf /usr/share/tomcat7