Installing latest nginx from official repository

Nginx was publicly released in 2004. Nginx is lightweight footprint and its ability to scale easily on minimal hardware. NGINX can manage thousands of connection on a single-threaded processes known as workers, which demand minimal CPU and RAM resources.

Before installing the nginx on server , lets check the latest available package of nginx on official ubuntu repository

sudo apt show nginx

It is 1.18.0 at the time of writing this article, however the official nginx repository have currently 1.26.0 as the latest package. In this blog you will learn to install the latest nginx from the official repository

Now we need the signing key to verify the  nginx package which we want to install,  Follow the following steps:

Install the prerequisites:

sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring -y

Fetch the key:

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

set up the apt repository for stable nginx packages

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list

Set the priority to download nginx package from this new stable repository:

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99nginx

Now refresh the list of available packages:

sudo apt update

Run Nginx installation command:

sudo apt install nginx

Verify the packages available in the repository using the following commnad:

sudo apt-cache policy nginx

Currently 1.26.0 is installed on server. If you look below closely , area highlighted in red is the official repository which contains the latest package of nginx version 1.26.0. The one highlighted in yellow is the ubuntu’s repository which contains version 1.18.0 version

Verify the installation version:

sudo nginx -v

Run the following command to start nginx service

sudo systemctl start nginx

Open the public ip address of the VM. default page of nginx will be loaded.

Complete Nginx cookbook
Direct Download