Added on Jul 17th, 2012 and marked as install nginx server web

The nginx release on the Ubuntu repositories can be several versions behind the official stable release (not to mention the development release).

A repository exists that contains the official stable and development releases of nginx. Lets make sure we use this version instead of the default Ubuntu version.

First, make sure we can add a repository by installing the Python Software Properties:

apt-get install python-software-properties

Now, add the repository:

add-apt-repository ppa:nginx/stable
apt-get update

(What if add-apt-repository is not found?)

You install nginx just as usual:

apt-get install nginx

Upgrading to the latest version

If you already installed nginx, but did not use the method mentioned here, it still is possible to upgrade to the latest version.

Add the repository as mentioned above, but before installing nginx lets have a look at the installed packages:

dpkg --list | grep nginx

From this:

ii  nginx           1.1.19-1    small, but very powerful and efficient web server and mail proxy
ii  nginx-common    1.1.19-1    small, but very powerful and efficient web server (common files)
ii  nginx-full      1.1.19-1    nginx web server with full set of core modules

you see that 3 packages are installed, each with a version of 1.1.19-1. When you do

apt-get install nginx

only the first package will be updated, but you also need to upgrade the other packages. This is done by installing nginx-full:

apt-get install nginx-full

Now you have nginx running on the latest stable version. Using the same method you can upgrade the latest development version.

Downgrading to the Ubuntu version

If for some reason you want to return to the version provided by Ubuntu, that is also possible. First remove the repository from the sources file:

nano /etc/apt/sources.list
apt-get update

Now we have to remove the nginx packages:

apt-get remove nginx
apt-get remove nginx-full
apt-get remove nginx-common

And then install nginx again:

apt-get install nginx

Background information