Ubuntu – how to install nginx after removed it manually

nginx

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)

Best Answer

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
Related Question