Real Clear Computing

How to Uninstall Nginx in Ubuntu Server

Uninstall Nginx in Ubuntu Server

Before you install the latest version of Nginx on Ubuntu, you would want to remove the version of Nginx that is already running on your system.

You can run the following command to check whether Nginx is already installed on your Ubuntu System:

dpkg --get-selections | grep nginx

If the dpkg command returns an output as shown in the following image, then the Nginx is installed on your machine.

remove nginx ubuntu

To completely remove Nginx, run the following two commands one by one:

apt-get purge nginx* libnginx*
apt-get autoremove

After that, enter the dpkg --get-selections command once again. If any of Nginx related packages are yet remaining, uninstall them individually using the apt-get purge command.

The apt command does not remove a custom Nginx repository if you have added one to the /etc/apt/sources.list file or /etc/apt/sources.list.d directory. You have to remove them manually.

It is also recommended that you restart Ubuntu before installing Nginx again.