Apache Tomcat or simply Tomcat (formerly it was also known as Jakarta Tomcat) is an open source web server and servlet container developed by the Apache Software Foundation (ASF). Tomcat can be installed on CentOS/Redhat machine either using yum or from the source file. However, in this tutorial, we will see, how we can uninstall/remove tomcat from the Linux machine.

In order to remove tomcat from your machine, the first thing you need to check is how this package got installed on your server.

Removal of Tomcat installation through package manager

Using yum

Suppose, you have installed tomcat 5 or tomcat 7 using yum package manager, then the default tomcat configurations can be found at “/etc/tomcat5” and “/usr/share/tomcat5”. You can find the tomcat packages using the following command:

# rpm –qa | grep tomcat

Now, you can proceed with uninstallation of the listed packages using “yum” as follows:

# yum remove tomcat5
# yum remove tomcat5-webapps
# yum remove tomcat5-admin-webapps

Continue this for the other packages. Packages such as tomcat5-servelet may have many dependencies including open office. So, if you want to remove the packages without removing the dependencies, you need to use the command “rpm” as follows:

# rpm –e package_name –nodeps

After removing the packages, you need to remove the tomcat directories too:

# rm –rf /etc/tomcat5
# rm –rf /usr/share/tomcat5

Using Apt

On Ubuntu to remove system and config files run below commands

sudo apt remove --purge tomcat7 tomcat7-docs
sudo apt autoremove
sudo apt autoclean

You can locate and manually delete the remaining files if any exists.

sudo apt install locate && sudo updatedb
locate tomcat

Using Apt-get

To remove just the tomcat7 package

sudo apt-get remove tomcat7

To remove tomcat7 package and its dependent packages

sudo apt-get remove --auto-remove tomcat7

This will delete all local/config files and cant be restored

sudo apt-get purge tomcat7
sudo apt-get purge --auto-remove tomcat7

Removal of Tomcat source file installation

In this case, you need to stop tomcat and remove all the binaries from the server.

1. To stop tomcat

Lets first stop the service.

#/usr/sbin/stoptomcat

2. To remove tomcat binaries and folders

Remove all occurence of tomcat binary files and folders from the below locations

#rm -f /usr/sbin/startomcat
#rm -f /usr/sbin/stoptomcat
#rm -Rf /usr/local/jakarta

3. To remove from ‘chkservd’

Stop chkservd and remove tomcat from there if it is configured.

# service chkservd stop
#cd /etc/chkserv.d
#rm -Rf tomcat
#cd /var/run/chkservd
rm -Rf Tomcat_JSP
#service chkservd start

4. To remove Tomcat Connector configuration from Apache web server

Remove all mod_jk lines from httpd.conf, including addmodule, loadmodule, and include lines.

References

Leave a Reply

Your email address will not be published. Required fields are marked *