How to uninstall and remove Apache2 on Ubuntu or Debian

It turns out that uninstalling Apache2 web server is not as straightforward as installing it. You will need to remove Apache2 package itself, as well as other dependent packages and its associated configurations. Here is how you remove Apache2 cleanly on Ubuntu and Debian.

The first step is to stop any running instance of Apache2, because Apache2 will not be properly removed while it is running.

$ sudo service apache2 stop

Then uninstall Apache2 and its dependent packages. Use purge option instead of remove with apt-get command. The former option will try to remove dependent packages, as well as any configuration files created by them. In addition, use autoremove option as well, to remove any other dependencies that were installed with Apache2, but are no longer used by any other package.

$ sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
$ sudo apt-get autoremove

Finally, check if there is any configuration files or manual pages belonging to Apache2, which are still not removed.

$ whereis apache2
apache2: /etc/apache2

In this example, /etc/apache2 directory still exists. Since this directory (as well as any configuration files in it) is no longer necessary, go ahead and remove it manually.

$ sudo rm -rf /etc/apache2

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

7 thoughts on “How to uninstall and remove Apache2 on Ubuntu or Debian

  1. I loaded Lampp Package after a failed (incomplete) load of Apache2 for local development.
    Nice package with mysql, perl, etc all functioning.

    Do you suppose I'd be at risk removing Apache2? I have to kill it each time I reboot so Lampp will run with my datasbase.

    Lammp is at the root
    Apache2 is at the root


  2. I am new to ubuntu and linux and you really helped me to learn the basic skill of removing and purging programs from the command line. Thanks so much. Keep up the good work

Leave a comment

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