How to completely uninstall NGINX from your system

Updated: January 19, 2024 By: Guest Contributor Post a comment

Introduction

NGINX is a popular web server that’s renowned for its performance and flexibility. However, there may come a time where you no longer require its services or need to replace it with a different solution. In this guide, we’ll walk through the steps to completely uninstall NGINX from your system. We will cover various methods appropriate for different operating systems. By the end of this tutorial, you’ll know how to clear your system of all traces of NGINX.

Prerequisites

Before starting the uninstallation process, ensure that:

  • You have access to a user account with sudo or root privileges.
  • You have backed up any critical configuration files or data if you wish to preserve them.
  • NGINX is not running, or you have planned for potential downtime of any services relying on it.

Uninstalling NGINX on Ubuntu/Debian-based Distributions

On Debian-based systems like Ubuntu, uninstalling NGINX is managed with the ‘apt-get’ package manager.

sudo apt-get remove nginx nginx-common

This command will remove NGINX and its common files but leave behind configuration files and certain dependencies. To completely remove NGINX along with its configuration files, you can use the ‘purge’ option:

sudo apt-get purge nginx nginx-common

To get rid of any remaining dependencies that are no longer needed, run:

sudo apt-get autoremove

Additionally, check for any remaining NGINX files, such as in ‘/etc/nginx/’ or ‘/var/log/nginx/’, and remove them manually:

sudo rm -rf /etc/nginx/
sudo rm -rf /var/log/nginx/

Outputs following these commands will indicate the successful removal of NGINX and related files.

Uninstalling NGINX on Red Hat/CentOS-based Distributions

If you’re running a Red Hat or CentOS-based system, you’ll use ‘yum’ to remove the software:

sudo yum remove nginx

To clean up residual config files and dependencies, you should:

sudo yum autoremove

And again, check manually for any lingering directories and files, then use the ‘rm’ command to remove them:

sudo rm -rf /etc/nginx/
sudo rm -rf /var/log/nginx/

Ensure all services that required NGINX have been stopped before executing these commands.

Uninstalling NGINX on Fedora

The newer versions of Fedora utilize ‘dnf’ as the package manager:

sudo dnf remove nginx

Afterward, to ensure all unused dependencies are removed, you should run:

sudo dnf autoremove

Manually inspect directories and clean lingering files as before:

sudo rm -rf /etc/nginx/
sudo rm -rf /var/log/nginx/

Confirm all changes by querying ‘dnf’:

sudo dnf list installed | grep nginx

You should see no remaining NGINX packages, indicating a complete uninstall.

Uninstalling NGINX on macOS

If you’ve installed NGINX via Homebrew on macOS, the following command will uninstall the server:

brew uninstall nginx

Homebrew does a good job of cleaning up dependencies, but for manual cleanup, check:

sudo rm -rf /usr/local/etc/nginx/

In the rare case you installed NGINX from source or via other means, you’ll need to delete the directories where NGINX was installed, and check for launch agents or daemons.

Uninstalling NGINX on Windows

For Windows users, NGINX doesn’t come with a built-in uninstaller. Terminate any NGINX processes from the Task Manager, then simply delete the folder where NGINX was installed, typically:

del /s /q C:\nginx
rmdir /s /q C:\nginx

If NGINX was installed as a service, you’d also want to remove the service:

sc delete nginx

Afterward, amend your system environment PATH if necessary and check the Service Management Console (‘services.msc’) to confirm NGINX is no longer listed.

Advanced Cleanup Operations

In some cases, particularly if NGINX was compiled from source or heavily customized, you may need to execute more in-depth cleaning operations. This could involve searching for files associated with NGINX across your system and manually inspecting and purging them. However, these actions should be performed with caution and deep familiarity with your system’s directory structure and configuration.

Conclusion

In conclusion, uninstalling NGINX from your system can be performed cleanly and entirely through command-line operations adjusted for your specific OS packaging tool. Care should always be taken while deleting any additional dependencies and configuration files to not affect the system adversely.