Uninstall Nginx Completely on Debian/Ubuntu-Based Linux

mail
Cyrus Kao

This guide will cover how to completely uninstall Nginx web server (including its dependencies, modules, configuration files and logs) on Debian/Ubuntu-based Linux distros (e.g. Linux Mint, Pop!_OS, Elementary OS). It's useful when you're trying to reinstall a clean Nginx server.

/usr/sbin/nginx
Nginx (/usr/sbin/nginx) running in the background

Stop Service

In case Nginx server is still running, let's stop the Nginx service (nginx.service) first:

sudo systemctl stop nginx
Bash

Uninstallation

In this step we'll uninstall Nginx and its related packages from our system.

Main Packages

Purge the main Nginx packages:

sudo apt purge nginx*
Bash

Dependencies

Remove the unused dependencies with autoremove:

sudo apt autoremove
Bash

Clean Up

Although Nginx is now uninstalled, there are still some files generated by Nginx left to clean.

Configuration Files (Optional)

Remove the configuration files in /etc/nginx:

sudo rm -rf /etc/nginx
Bash

Logs (Optional)

Remove the logs in /var/log/nginx

sudo rm -rf /var/log/nginx
Bash

See Also

Comments

0500