Installing Nginx Mainline and Stable Versions on Ubuntu 17.04

programming 3173456 640 1

Want to install Nginx webserver on Ubuntu? It’s pretty easy. In fact, Nginx webserver packages are in Ubuntu’s default repositories. All one has to do is run the apt-get install nginx command to install Nginx on Ubuntu.

Few things that some folks are not aware of is that the version of Nginx that comes with Ubuntu are sometime pretty old, albeit stable. Ubuntu only includes stable versions of Nginx in its systems’ repositories.

If you want to install the latest and newest versions of packages that are not currently in Ubuntu, you may have to add Nginx’s repositories to Ubuntu and install these packages from there. This brief tutorial is going to show you how to do just that.

Nginx packages are shelved  in two branches or repositories. These are Mainline and Stable repositories.

The mainline repositories contains the latest packages and newest features that are available to install, while the stable branch or repository contains packages and features that have been tested and ready for production.

The Mainline repository contains packages of both Stable and Mainline repositories. Stable repository contains packages only available in the stable branch.

I have always installed Nginx packages from its Mainline branch in production. and have never had any issues. So, if you need the latest and greatest features available to Nginx, install it from its Mainline repository.

Step 1: Installing from Nginx Mainline Repository

To install Nginx web server from its Mainline repository, run the commands to add Nginx’s repository key to Ubuntu. You’ll need to install the key in order for Ubuntu to trust packages from that repository.

cd /tmp/ && wget

After adding the key, run the commands below to install Nginx’s Mainline repository or branch on Ubuntu.

sudo sh -c "echo 'deb '$(lsb_release -cs)' nginx' > /etc/apt/sources.list.d/Nginx.list"

When you’re done, all you need to so is run the commands below to install the latest version of Nginx.

sudo apt-get update
sudo apt-get install nginx

Step 2: Installing Nginx from its Stable Repository

Another option is to install Nginx from its stable branch or repository. To install Nginx from the stable branch, run the commands below to install Nginx stable repository on Ubuntu.

sudo sh -c "echo 'deb '$(lsb_release -cs)' nginx' > /etc/apt/sources.list.d/Nginx.list"

This assumes you have already added Nginx’s repository key to Ubuntu by running the first commands above.

After adding the repository key, run the commands below to install Nginx.

sudo apt-get update
sudo apt-get install nginx

That’s how one installs Nginx webserver on Ubuntu systems.


Although anyone can install Nginx on Ubuntu without installing its repository first, if you need the latest version as soon as their released, you will have to install Nginx repository. When you do that, Ubuntu will fetch all the repositories install on the systems and downloads the latest versions as them become available.

So, follow the steps above to install the repository and whenever newer versions of Nginx are released you’ll get them quickly.


You may also like the post below:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.