Ubuntu 16 install and uninstall nginx

In this post:

  • Install default nginx
    • sudo apt-get install nginx
  • Uninstall default nginx

If you want to reinstall nginx you will need first to uninstall it and then to install it again. Installing default nginx is easy and can be done with several console commands. The same is for uninstall. Installing Nginx from sources requires better knowledge and more time.

Install default nginx

Installing default nginx on Ubuntu is done by:

sudo apt-get update
sudo apt-get install nginx

Check if nginx is installed by:

systemctl status nginx

Starting, stopping and restating nginx can be done with:

sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl restart nginx

The downside is that it will install older version and if you want to have more recent one you will need:

  • build one from sources
  • upgrade your linux (to Ubuntu 18 is preferable as it's the next LTS which will be release in April 2018)
  • add custom repository

Uninstall default nginx

First line is going to delete the installation except config files. Second one removes everything. You need to choose one of them. Third one will remove dependencies used by nginx which are no longer required.

sudo apt-get remove nginx nginx-common 
sudo apt-get purge nginx nginx-common
sudo apt-get autoremove