It seems a simple apt-get remove apache2 does not completely remove apache2 as I can still see it on one of the processes when running top. How does one remove apache2 completely on his ubuntu server?

It's not removed indeed:

~# which apache2
/usr/sbin/apache2
~# whereis apache2
apache2: /usr/sbin/apache2 /etc/apache2 /usr/lib/apache2 /usr/share/apache2 /usr/share/man/man8/apache2.8.gz

But when I do apt-get remove apache2 again:

# apt-get remove apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package apache2 is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
  • 3
    run apt-get purge apache2. It will remove the all config files. – Manula Waidyanatha Aug 17 '12 at 10:06
up vote 140 down vote accepted

apache2 is a metapackage that just selects other packages. If you installed apache by installing that package, you just need to run this to clean up the automatically selected packages:

sudo apt autoremove

If that doesn't work, you might have installed one of the dependents manually. You can target all the apache2- packages from space and nuke the lot:

sudo apt remove apache2.*

For future reference, to find out which package a binary is from, you can run this:

dpkg -S `which apache2`

I'd expect that to come back with apache2.2-bin (at the time of writing).

  • 5
    also, use --purge if you want the configuration files to be deleted as well: apt-get --purge remove apache2 – xyious Aug 17 '12 at 10:03
  • 1
    The last command outputs apache2-mpm-prefork: /usr/sbin/apache2 – Jürgen Paul Aug 17 '12 at 10:03
  • 1
    @Severus fair enough -- I was just guessing but that makes sense. Yeah I'd just use the wildcard but keen an eye on what it's going to delete. apache2-common is used by some tools that aren't the apache2 httpd so you might need to reinstall some thing after. – Oli Aug 17 '12 at 10:06
  • @Oli Removing things with a regex 'apache2*' is dangerous, loads of things end up getting removed – jhbsk Dec 8 '13 at 7:57
  • 1
    @jasdeepkhalsa It's not "dangerous". apt-get (unlike apt-cache) limits its searches to names-only so it's not that far-reaching. Everything it captures is Apache or Apache dependent. Check it yourself with apt-get -s remove apache2* – Oli Dec 9 '13 at 8:53

Follow these steps to remove the apache2 service using Terminal:

  1. First stop the apache2 service if it is running with: sudo service apache2 stop
  2. Now remove and cleanup all the apache2 packages with:

    sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
    //or 
    sudo apt-get purge apache2 apache2-utils apache2-bin apache2.2-common
    
  3. Finally, run sudo apt-get autoremove just in case any other cleanup in needed

You can do the following two tests to confirm apache has been removed:

  1. which apache2 - should return a blank line
  2. sudo service apache2 start - should return apache2: unrecognized service
  • 3
    sudo apt-get purge apache2 apache2-utils apache2-bin apache2.2-common – Hermann Ingjaldsson Nov 7 '17 at 13:49

A very simple and straightforward way that worked for me is as follows:

  1. Stop apache2.

    sudo service apache2 stop
    
  2. Uninstall Apache2 and its dependent packages.

    sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
    
  3. Use autoremove option to get rid of other dependencies.

    sudo apt-get autoremove
    
  4. Check whether there are any configuration files that have not been removed.

    whereis apache2
    
  5. If you get a response as follows apache2: /etc/apache2 remove the directory and existing configuration files.

    sudo rm -rf /etc/apache2  
    

Source: How to uninstall and remove Apache2 on Ubuntu or Debian by Dan Nanni

  • 1
    For me it was: sudo apt-get purge apache2 apache2-utils apache2-bin apache2.2-common – Hermann Ingjaldsson Nov 7 '17 at 13:48

First check if you are using right package name, IMO correct package name is : apache2.x-common

If you want to completely remove the package including config files then try:

    dpkg --purge apache2.2-common

Take time to check if you are using the different package apache2.2-bin for Ubuntu 16.04 the latest is apache2.4-bin

sudo apt-get purge apache2 apache2-utils apache2.4-bin apache2.4-common

simply delete file apache2 under /etc/init.d/apache2 .. but first you'll need to do this :

sudo service apache2 stop

sudo chown user /etc/init.d/apache2
sudo chmod 755 /etc/init.d/apache2
sudo rm /etc/init.d/apache2 

it's worth for me :)

  • 6
    Nope, this wont remove apache. – Braiam Feb 21 '14 at 4:42
  • 4
    Yeah don't do this, don't do this at all! – Urda May 9 '14 at 21:02
  • It does help at times when you have uninstalled it incorrectly – Birju Shah Mar 20 '15 at 14:16

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.