Introduction

If you would like to install Nginx on Ubuntu, you can use the Nginx versions from the Ubuntu package repository, but the disadvantage is, that there are mostly older version of the fast web server. There is also the possibility to install Nginx from other sources by adding other repositories. In this case you will always have the newest version for your Ubuntu. I have created a few shell scripts, which install everything you need.

Installing Nginx from the default Ubuntu repositories:

sudo apt-get install nginx

Note:

In the following part you will find shell scripts which you have to execute with sudo. You just need to copy and execute them. The scripts are adding the official Nginx repository as source to the package manager and install Nginx afterwards.

Install Nginx on Ubuntu 12.04 LTS Precise Pangolin:

#!/bin/bash

######################################################
# Install Nginx on Ubuntu 12.04 LTS Precise Pangolin #
######################################################

# allways update the sources first
apt-get update
apt-get upgrade -y

# change to root directory
cd /root

# get the nginx repository key
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key

# remove the key again
rm nginx_signing.key

# add the repository to the source.list
echo
echo "# Repositories for nginx" >> /etc/apt/sources.list
echo "deb http://nginx.org/packages/ubuntu/ precise nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/ubuntu/ precise nginx" >> /etc/apt/sources.list

# update the repositories
apt-get update
apt-get install -y nginx

Install Nginx on Ubuntu 12.10 Quantal Quetzal:

#!/bin/bash

##################################################
# Install Nginx on Ubuntu 12.10 Quantal Quetzal  #
##################################################

# allways update the sources first
apt-get update
apt-get upgrade -y

# change to root directory
cd /root

# get the nginx repository key
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key

# remove the key again
rm nginx_signing.key

# add the repository to the source.list
echo
echo "# Repositories for nginx" >> /etc/apt/sources.list
echo "deb http://nginx.org/packages/ubuntu/ quantal nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/ubuntu/ quantal nginx" >> /etc/apt/sources.list

# update the repositories
apt-get update
apt-get install -y nginx

Install Nginx on Ubuntu 13.04 Raring Ringtail:

#!/bin/bash

##################################################
# Install Nginx on Ubuntu 13.04 Raring Ringtail  #
##################################################

# allways update the sources first
apt-get update
apt-get upgrade -y

# change to root directory
cd /root

# get the nginx repository key
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key

# remove the key again
rm nginx_signing.key

# add the repository to the source.list
echo
echo "# Repositories for nginx" >> /etc/apt/sources.list
echo "deb http://nginx.org/packages/ubuntu/ raring nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/ubuntu/ raring nginx" >> /etc/apt/sources.list

# update the repositories
apt-get update
apt-get install -y nginx

Install Nginx on Ubuntu 13.10 Saucy Salamander:

#!/bin/bash

##################################################
# Install Nginx on Ubuntu 13.10 Saucy Salamander #
##################################################

# allways update the sources first
apt-get update
apt-get upgrade -y

# change to root directory
cd /root

# get the nginx repository key
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key

# remove the key again
rm nginx_signing.key

# add the repository to the source.list
echo
echo "# Repositories for nginx" >> /etc/apt/sources.list
echo "deb http://nginx.org/packages/ubuntu/ saucy nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/ubuntu/ saucy nginx" >> /etc/apt/sources.list

# update the repositories
apt-get update
apt-get install -y nginx

Install Nginx on Ubuntu 14.04 LTS Trusty Thar:

#!/bin/bash

##################################################
# Install Nginx on Ubuntu 14.04 LTS Trusty Thar  #
##################################################

# allways update the sources first
apt-get update
apt-get upgrade -y

# change to root directory
cd /root

# get the nginx repository key
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key

# remove the key again
rm nginx_signing.key

# add the repository to the source.list
echo
echo "# Repositories for nginx" >> /etc/apt/sources.list
echo "deb http://nginx.org/packages/ubuntu/ trusty nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/ubuntu/ trusty nginx" >> /etc/apt/sources.list

# update the repositories
apt-get update
apt-get install -y nginx