NGINX Installation

This article has you adding the official NGINX package repository and adding the nginx package.


To read the installation instructions provided by NGINX look over the NGINX Ubuntu Installation Article .

Install Tools Used in Installation

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

Download and Add the nginx_signing.key:

curl | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg > /dev/null

Check the Contents of the nginx_signing.key:

gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

Desired Output of the nginx_signing.key:

pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
uid                      nginx signing key <[email protected]>

Add NGINX Package Repository:

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

Configure Package Repository

Set up repository pinning to prefer our packages over distribution-provided ones:

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

Update Package Repository List and Install nginx Package:

sudo apt update
sudo apt install nginx


which nginx
nginx -version


which nginx &amp;&amp; nginx -version output

Upon a successful installation you should see the location of the nginx binary and the version of the installed nginx package with the preceding commands.

Managing the nginx.service

NGINX automatically creates a service upon installation. The nginx.service can be controlled with the systemctl package.

For now we will be turning off and disabling the nginx.service. We will learn more about this in a later lesson.

Stop Service

sudo systemctl stop nginx

Disable Service

sudo systemctl disable nginx