can't remove ngnix

I want to get rid of nginx as it gives me troubles with apt-get but I can't get rid of it, I keep getting:

$ sudo apt remove nginx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'nginx' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up nginx-core (1.10.3-0ubuntu0.16.04.2) ...
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
invoke-rc.d: initscript nginx, action "start" failed.
? nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2018-05-22 06:49:55 PDT; 5ms ago
  Process: 30212 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 30208 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

May 22 06:49:54 regDesktopHome nginx[30212]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
May 22 06:49:54 regDesktopHome nginx[30212]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use)
May 22 06:49:54 regDesktopHome nginx[30212]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
May 22 06:49:55 regDesktopHome nginx[30212]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use)
May 22 06:49:55 regDesktopHome nginx[30212]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
May 22 06:49:55 regDesktopHome nginx[30212]: nginx: [emerg] still could not bind()
May 22 06:49:55 regDesktopHome systemd[1]: nginx.service: Control process exited, code=exited status=1
May 22 06:49:55 regDesktopHome systemd[1]: Failed to start A high performance web server and a reverse proxy server.
May 22 06:49:55 regDesktopHome systemd[1]: nginx.service: Unit entered failed state.
May 22 06:49:55 regDesktopHome systemd[1]: nginx.service: Failed with result 'exit-code'.
dpkg: error processing package nginx-core (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 nginx-core
E: Sub-process /usr/bin/dpkg returned an error code (1)
$ systemctl status nginx.service
? nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2018-05-22 06:49:55 PDT; 1min 45s ago
  Process: 30212 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 30208 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
$ journalctl -xe
Hint: You are currently not seeing messages from other users and the system.
      Users in the 'systemd-journal' group can see all messages. Pass -q to
      turn off this notice.
No journal files were opened due to insufficient permissions.
$ 

How can I get this resolved? I'm on 16.04

Answers 1

  • In this solution I suppose you have installed nginx from package (not from sources).

    1. Get list of installed packages like 'nginx': sudo apt list --installed 2>/dev/null |grep -i 'nginx'

    2. Review this list and remove packages. There are multiple ones for 'nginx': nginx, nginx-extras, nginx-full, nginx-light etc.

    First command will show you what exact nginx package(s) do you have on your system. Than you can continue to remove it/them.