Nginx – How to install nginx 1.9.5 on debian jessie

aptdebian-jessienginx

I added theses lines to the "/etc/apt/sources.list":

deb http://nginx.org/packages/mainline/debian/ jessie nginx
deb-src http://nginx.org/packages/mainline/debian/ jessie nginx

After that I've tried to update nginx with:

sudo apt-get clean && sudo apt-get install nginx

But I get the following error:

Unpacking nginx (1.9.15-1~jessie) over (1.6.2-5+deb8u1) ...
dpkg: error processing archive /var/cache/apt/archives/nginx_1.9.15-1~jessie_amd64.deb (--unpack):
 trying to overwrite '/usr/share/nginx/html/index.html', which is also in package nginx-common 1.6.2-5+deb8u1
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nginx_1.9.15-1~jessie_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

What am I doing wrong? Thank you.

Best Answer

Run the below commands on your terminal:

sudo dpkg -P nginx-common
sudo apt-get install -f

If it shows any dependency problem when uninstalling the above nginx-common package, then purge nginx-common package along with its dependencies:

sudo apt-get purge nginx*

Before running the above command, don't forget to check the dependency packages which are going to be purged along with nginx.

sudo apt-get purge -s nginx*

Then you will be able to install NGinX.