How to uninstall nginx with apt
28th of March 2008
My colleague Jan showed me how to do this so I'm going to blog about it to not forget and perhaps by being here other people might be able to search and find the solution too. I installed nginx because I wanted to play with it as an alternative to apache on my laptop. Now I've played enough and I'm going to want to remove it. My first attempt didn't work:
peterbe@trillian:~ $ sudo apt-get --purge remove nginx Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: nginx* 0 upgraded, 0 newly installed, 1 to remove and 116 not upgraded. 1 not fully installed or removed. Need to get 0B of archives. After unpacking 528kB disk space will be freed. Do you want to continue [Y/n]? (Reading database ... 242827 files and directories currently installed.) Removing nginx ... Stopping nginx: invoke-rc.d: initscript nginx, action "stop" failed. dpkg: error processing nginx (--purge): subprocess pre-removal script returned error exit status 1 Starting nginx: invoke-rc.d: initscript nginx, action "start" failed. dpkg: error while cleaning up: subprocess post-installation script returned error exit status 1 Errors were encountered while processing: nginx E: Sub-process /usr/bin/dpkg returned an error code (1)
I tried this both before and after having stopped and started nginx. Nothing worked. The trick is to fiddle with the init script /etc/init.d/nginx and insert a exit 0 at the top so that it now starts like this:
#!/bin/sh exit 0
Once saved and you try apt-get --purge remove nginx it will work. It might warn you that /var/log/nginx aren't removed because they're not empty but you can safely remove them manually unless you want to keep them.