Installing Nginx from source on Debian

Posted on


Installing Nginx on Debian is easy, but that may be outdated. Since Debian is stable Linux distribution, we cannot blame them for this. That’s why we are going to install Nginx from source on Debian.

Nginx on Debian

1. Refresh the Debian system once.

sudo apt update

2. Installing needed packages.

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

3. Import an official nginx signing key so apt could verify the packages authenticity. Fetch the key:

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

4. Verify that the downloaded file contains the proper key:

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

The output should contain the full fingerprint as follows:

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

5. Choose which package to install — stable or mainline.

My suggestion would be stable for production and mainline for development only.

To set up the apt repository for stable nginx packages, run the following command:

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

If you would like to use mainline nginx packages, run the following command instead:

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

6. 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

7. To install nginx, run the following commands:

sudo apt update
sudo apt install nginx

Now use the Nginx webserver for any application and website.

Read related contents by similar tags:

Zoho Workplace

Leave a Reply

Your email address will not be published. Required fields are marked *