13

I have installed nginx using apt

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:nginx/stable
sudo apt-get install software-properties-common
sudo apt-get update
sudo apt-get install nginx

Then I used whereis nginx and removed all files manually using rm now I wanna re-install nginx but it doesn't work and returning error:

awk: cannot open /etc/nginx/nginx.conf (No such file or directory)

I create /etc/nginx/nginx.conf then use apt-get install nginx it installed completely doesn't work.

output of sudo dpkg -l | grep nginx:

ii  nginx                                      1.4.3-1~raring0                        all          small, powerful, scalable web/proxy server
ii  nginx-common                               1.4.3-1~raring0                        all          small, powerful, scalable web/proxy server - common files
ii  nginx-full                                 1.4.3-1~raring0                        i386         nginx web/proxy server (standard version)
Saurav Kumar
  • 14,916
april
  • 131
  • 1
  • 1
  • 4
  • The way you used to remove nginx was not the correct way to remove any package in ubuntu. You'd to remove it using same apt-get command. Let me post the proper way to remove it completely and and how to install it again. – Saurav Kumar Oct 19 '13 at 16:15
  • i know that lately but how i can fix it know and i do the same for remove apatch2 – april Oct 19 '13 at 16:19
  • April, please check my answer once. Also try to re-start your system once with still it doesn't work! – Saurav Kumar Oct 19 '13 at 16:31
  • its not work and whereis nginx return nothing – april Oct 19 '13 at 16:53

2 Answers2

20

Since you managed to install it anyhow first thing you've to do is to remove it completely with the configuration files

Follow these steps to remove it completely and install it again.

  • Open terminal and execute these commands:

    sudo apt-get autoremove nginx
    sudo apt-get --purge remove nginx
    sudo apt-get autoremove && sudo apt-get autoclean
    sudo find / | grep nginx | sudo xargs rm -rf
    

    the last command will remove the repository also so you've to add it again by:

    sudo add-apt-repository ppa:nginx/stable
    

    Now try to install it again by:

    sudo apt-get update && sudo apt-get -f install nginx
    
  • Hope it would solve your issue. Reply if you get any error at any particular command describing the command.

This is the output of

sudo dpkg -l | grep nginx:

ii  nginx                                       1.4.3-1~precise0                                    small, powerful, scalable web/proxy server
ii  nginx-common                                1.4.3-1~precise0                                    small, powerful, scalable web/proxy server - common files
ii  nginx-full                                  1.4.3-1~precise0                                    nginx web/proxy server (standard version)

whereis nginx:

nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx /usr/share/man/man1/nginx.1.gz
Saurav Kumar
  • 14,916
  • Did you get any error message while installing nginx? Also post the output of this command in your question: sudo dpkg -l | grep nginx – Saurav Kumar Oct 19 '13 at 18:05
  • every think seam okey it must work but i think i delete some system file when i write whereis nginx and delete all result – april Oct 19 '13 at 18:49
  • can you post output of whereis nginx ? – april Oct 19 '13 at 18:50
  • no errors only this warning

    dpkg: warning: files list file for package 'nginx-common' missing; assuming package has no files currently installed

    dpkg: warning: files list file for package 'nginx-full' missing; assuming package has no files currently installed

    W: Duplicate sources.list entry http://dl.google.com/linux/chrome/deb/ stable/main i386 Packages (/var/lib/apt/lists/dl.google.com_linux_chrome_deb_dists_stable_main_binary-i386_Packages)

    – april Oct 19 '13 at 19:08
  • April, I've edited my answer.. – Saurav Kumar Oct 19 '13 at 19:15
  • April, I think there is some residual packages left in your system. To insure this paste the output of this command: sudo dpkg -l | grep "^rc" Reply.. – Saurav Kumar Oct 19 '13 at 19:21
  • @EliahKagan I have noticed many time sudo apt-get --purge remove removed many unnecessary and unwanted files which had been installed at the time of package installation. You may say those as supportive packages. I just wrote purge to completely remove nginx. And it worked for me. Though if you have any suggestion you are most welcomed :) Thanks.. – Saurav Kumar Sep 06 '14 at 05:36
  • @SauravKumar Yes, I agree sudo apt-get --purge remove ... (or the equivalent sudo apt-get purge ...) can be helpful. But I'm not sure it always does anything if the package or package list being purged (which I've been calling ...) has already been removed. Sometimes it does, but I seem to recall sometimes having to run sudo dpkg -P ... instead. Unfortunately I don't really have any alternatives or improvements to suggest: instead, I was hoping you (or someone else reading) might know if sudo apt-get purge ... always works for removing conffiles of already uninstalled packages. – Eliah Kagan Sep 06 '14 at 12:03
12

The problem you had is that you removed some files that don't belong to package nginx, the package that installs /etc/nginx files is nginx-common.

So if you want to recreate the /etc/nginx files, you should do:

> apt-get install --reinstall nginx-common

In order to determine to which package belongs a file, you should execute dpkg -S <file>, in this case:

dpkg -S /etc/nginx
nginx-common: /etc/nginx
tvs
  • 328