UbuntuApacheLinux VPSServer Management

How to Uninstalling Apache on Ubuntu: A Comprehensive Guide

In our previous guide, “A Comprehensive Guide: How to Installing and Configuring Apache on Ubuntu” we explored the process of setting up and configuring the Apache web server, a powerful tool for hosting websites and applications. However, there may come a time when you need to remove Apache from your Ubuntu server. Whether it’s to transition to a different web server, troubleshoot issues, or simply clean up your system, uninstalling Apache is a crucial skill for server administrators.

In this comprehensive guide, we’ll walk you through the process of completely uninstalling Apache from your Ubuntu system. We’ll ensure that all related packages, configurations, and dependencies are removed, leaving your server clean and ready for whatever comes next.


Before you start the uninstallation process, make sure you have:

  1. Access to a Ubuntu server with Apache installed.
  2. Administrative (sudo) privileges to execute commands.

Let’s proceed with the uninstallation process:

Step 1: Stop the Apache Service

Before uninstalling Apache, it’s essential to stop the Apache service to prevent any running processes. Use the following command to stop Apache:

sudo systemctl stop apache2

Step 2: Remove Apache Packages

To uninstall Apache, you need to remove the Apache packages. Use the apt package manager to do this. First, list all the Apache-related packages to determine which ones need removal:

dpkg -l | grep apache

This will display a list of Apache packages with their status. To remove these packages, use the apt-get purge command for each package:

sudo apt-get purge <package-name>

To remove the apache2 package completely, you’d run:

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

Repeat this step for each package you identified in the previous step.

Step 3: Remove Configuration Files (Including Checking for Leftover Configuration Files)

Even after purging the Apache packages, some configuration files might remain on your system. To ensure that all configuration files are removed, follow these steps:

Check whether there are any configuration files that have not been removed:

whereis apache2

If you get a response like apache2: /etc/apache2, it means there are leftover configuration files. In this case, you should remove the directory and existing configuration files:

sudo rm -rf /etc/apache2

By following these steps, you can ensure that all Apache configuration files are properly removed from your system.

Step 4: Autoremove Unused Packages

After removing the Apache packages and their configuration files, it’s a good practice to run apt-get autoremove to remove any residual packages that were installed as dependencies but are no longer needed:

sudo apt-get autoremove

Step 5: Clean Up

To complete the Apache uninstallation, clean up any remaining Apache files and directories. Use the following commands to remove the Apache web root and log files:

sudo rm -rf /var/www/html && sudo rm -rf /var/log/apache2

Step 6: Verify Apache Removal

To verify that Apache has been successfully uninstalled, try running the following command:

apache2 -v

If Apache has been removed, you should see an error message stating that the command is not found.

One Command Uninstall

To uninstall Apache2 and its related packages completely in one command, you can use the following command, which combines the steps mentioned earlier:

sudo systemctl stop apache2 && sudo apt-get purge apache2 apache2-utils apache2-bin apache2.2-common && sudo rm -rf /etc/apache2 && sudo apt-get autoremove && sudo rm -rf /var/www/html && sudo rm -rf /var/log/apache2

This command performs the following actions in one line:

  1. Purges the Apache2 and related packages.
  2. Lists and purges configuration files for removed packages.
  3. Performs an autoremove to remove any residual packages.
  4. Cleans up any remaining Apache2 files and directories.

Please exercise caution when using this command, as it will remove Apache2 and all its related data without further confirmation.


Uninstalling Apache from your Ubuntu server is a straightforward process, but it’s crucial to follow these steps carefully to ensure all related files and configurations are removed. By completing this process, you can free up system resources and cleanly uninstall Apache from your server, allowing you to explore other web server options or troubleshoot any issues you might be facing.


I love to talk on trending ⚡ technology ⚡, I have huge attraction on 😁 Linux 😅 and I am a bit 😄 mad 😄 when I code.

Related Articles

Leave a Reply

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

Back to top button