Add repository and install NGINX webserver on Ubuntu

Want the fastest open source web server ever?

logo-nginxThis tutorial will show you how to install and setup the latest version of the open source NGINX web server on an Ubuntu server (I am using 12.04). It is the second step in getting a LEMP stack — Linux, NGINX (pronounced Engine X), MySQL, PHP. NGINX is a lightweight, fast and very efficient web and proxy server. It is one of the fastest static conent web servers available and ca be deployed to delivery dynamic content through a FastCGI interface. On the 3rd of April 2014 W3Techs reported that 23% of the top 1 million and 30.3% of the top 100k sites on the web use NGINX. For more details about NGINX visit

→ A Linux (Ubuntu) server that has gone through the initial server setup and has no web server installed yet.
→ Know how to connect to your server (Terminal, Putty,…)
Step 1: Get everything ready

To install server programs we will use the installer apt-get. But before we start we will make sure that everything is properly upgraded and updated with the following command.

sudo apt-get update && time sudo apt-get dist-upgrade

This will do several things.

  • update. This will download all of the latest patched software to make sure that when you install something it is the latest stable and secure version.
  • dist-upgrade. This is used to install the newest versions of all packages currently installed on the system from the sources listed in /etc/apt/sources.list.
  • time. When the command apt-get finished, this command will display information about resources used by the command (i.e. time).
Quick tip: Whenever you are not sure what a certain command does, simply type “man COMMAND” to get detailed information (i.e. manual) about that particular command.
Step 2: Add the NGINX repository

Because the NGINX version that comes with the distribution most of the time isn’t the latest one, we will add a new repository to make sure that we always have the latest version.

First of all we need to install “python software properties”. This software provides an abstraction of the used apt repositories. It allows you to easily manage your distribution and independent software vendor software sources.

sudo apt-get install python-software-properties

After the command has executed successfully you can add the NGINX repository.

sudo add-apt-repository ppa:nginx/stable

To make sure that we have the latest patched software available for installation in our system, run the update command again.

sudo apt-get update
Step 3: Install NGINX

Now we can move on to installing NGINX on our server. More information can be found on .

sudo apt-get install nginx

It is possible that you have to hit ENTER or answer yes during the installation. After the installation has completed successfully you need to start NGINX as it doesn’t start on its own.

sudo service nginx start

After you have followed all the steps, you can check if it is installed correctly by pointing your browser to the IP address of your server. If do not know the IP address of your server by heart you can use the following command.

ifconfig eth0 | grep inet | awk '{ print $2 }'

You should see something like this for NGINX version 1.4.7., which is the most recent version as of April 2014.


Success! What’s next?

After successfully installing NGINX you should definitely check out the article on how to optimize the NGINX configuration. After that you can check out the guides that show how to install MariaDB or PHP5.

Leave a Comment.