How to Uninstall and Remove Apache2 on Debian

Apache2 is an open-source web server that helps users in developing web-based applications. However, running Apache2 on the system may put a security threat as it can become vulnerable to attacks. Thus, for improving the system security, it’s better to remove it from the system in case you don’t need its service any more.

If you have previously installed Apache2 on Debian, and want to remove or uninstall it you can follow this article’s guidelines to learn different ways to do it. 

Uninstall and Remove Apache2 on Debian

There are different ways to uninstall or remove Apache2 from Debian, which are as follows:

Method 1: Remove Apache2 Using apt purge Command

To remove Apache2 from Debian, you can use the apt purge command that removes Apache2 and associated dependencies from the system.

sudo apt purge apache2 apache2-utils

Method 2: Remove Apache2 Using apt remove Command

You can also remove Apache2 from Debian using the apt remove command. The command works similar to the above command as it removes Apache2 and its associated dependencies from the system.

sudo apt remove apache2 apache2-utils

Method 3: Remove Apache2 Using autoremove Command

If you want to completely remove Apache2 from the Debian with configuration settings, you can use the following apt autoremove command:

sudo apt autoremove apache2 apache2-utils

Method 4: Remove Apache2 by Deleting Source Directories

You can also remove Apache2 from Debian by deleting its source directories. You can find the Apache2 source directories location using the following command:

whereis apache2

Then remove those directories using the following command:

sudo rm -r <apache2 file location>

Note: There could be multiple directories, but the syntax to remove those directories remains the same.

Finally, to verify that everything is done as expected run the below-written command, and in the output, you should see no files, and this will confirm that Apache2 is uninstalled or removed completely from the system:

whereis apache2


To uninstall or remove the Apache2 on Debian, the user can use the apt purge, apt remove, and apt autoremove commands. The users can also delete source directories to remove Apache2 from Debian. However, before that, the user must need to find the Apache2 source directories using the “whereis apache2” command. Then to remove the directories the “rm -r” command is used.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.