Ubuntu – Nginx fails to update after upgrade to 16.04 server


I upgraded from 14.04 server to 16.04 server. I have always used the official nginx packages, because I needed support for things like SPDY and HTTP2 which were not in the 14.04 version of nginx. Now when I try to update, I get the following error message.

Preparing to unpack .../nginx_1.11.1-1~xenial_amd64.deb ...
Unpacking nginx (1.11.1-1~xenial) over (1.10.0-0ubuntu0.16.04.1) ...
dpkg: error processing archive /var/cache/apt/archives/nginx_1.11.1-1~xenial_amd64.deb (--unpack):
 trying to overwrite '/usr/share/nginx/html/index.html', which is also in package nginx-common 1.10.0-0ubuntu0.16.04.2
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)
Failed to perform requested operation on package.  Trying to recover:

In my sources.list file I have:

deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx

Any ideas how to resolve this issue?

Best Answer

This will likely fix it. I had this, and a couple of other problems myself.

  1. Move to /etc and copy the nginx directory for safety:

    cd /etc
    cp -R nginx/ nginx-bak/
  2. Remove the old version of nginx:

    apt-get remove nginx nginx-common
  3. Install the new nginx:

    apt-get install nginx
  4. Answer no to any prompts to overwrite configs.
  5. To enable and run nginx:

    systemctl unmask nginx.service
    systemctl start nginx.service
Related Question