Skip to content

Installation

Install using distro's repositories

On Ubuntu

Install using official repositories

On Ubuntu

These steps comes from Official nginx documentation1

From a bash prompt, start installing prerequisites

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

Then, import official packages' GPG key

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

Optional: GPG Key Verification

If you want to be sure that the GPG key is correct, run this command:

gpg --dry-run --quiet --no-keyring --import --import-options \
    import-show /usr/share/keyrings/nginx-archive-keyring.gpg
Expected output has to contain this:
pub   rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
    573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid                      nginx signing key <signing-key@nginx.com>

Enable apt repository for official stable 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

Setup priority for the newly added repository over Ubuntu's official repos

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

When done, start installation with:

sudo apt update && sudo apt install -y nginx