Install latest version of Nginx on Ubuntu

NginxI always run the latest LTS version of Ubuntu on all my servers. Unfortunately, the Nginx versions tend to be quite the bit behind the current release. So how do you get an updated, current version of without resorting to having to maintain the packages yourself? Luckily, the Nginx team have their own Ubuntu apt repository so it’s easy to keep current with the latest version of Nginx.

In general, you should deploy the NGINX mainline branch at all times.  You may wish to use stable if you are concerned about possible impacts of new features, such as incompatibility with third-party modules or the introduction of bugs in new features.

Source: NGINX 1.6 and 1.7 released – Which version should I use?

First, to avoid missing PGP key during installation and upgrades, install the Nginx team’s package signing key:

$ curl -s | sudo apt-key add -

Add the repo to your apt sources:

$ sudo echo -e "deb `lsb_release -cs` nginx\ndeb-src `lsb_release -cs` nginx" > /etc/apt/sources.list.d/nginx.list

Resynchronize the package index files from their sources:

$ sudo apt-get update

If you are installing nginx:

$ sudo apt-get install nginx

… or if you are upgrading:

$ sudo apt-get dist-upgrade

And you’re done :-)

Maybe you are also looking for how to install the latest version of PHP?
… or even replace PHP with HHVM.