How to install the latest nginx on Debian and Ubuntu

Josh Sherman
2 min read
Servers / Serverless Web Servers Debian / Ubuntu

It’s been a minute since I’ve built out a new server, specifically a web server.

As I ventured down the path of installing the latest version of nginx recently, I found the official documentation to be a touch lacking. The steps were clear enough, but the installation guide didn’t mention setting up the GPG signing key.

A bit of additional research yielded another official document that talked about the key and I thought it wouldn’t be a bad idea to document the installation steps in their entirety so future Josh doesn’t have to track down the signing key stuff again.

Worth noting, the following commands should be run as a super user.

For Debian 8.x, 9.x and 10.x+

Step 1: Add the source repository.

Be sure to replace codename with the code name for the version of Debian you’re running.

Most likely will work for future versions of Debian past buster.

cat <<EOF >> /etc/apt/sources.list.d/nginx.list
deb http://nginx.org/packages/debian/ codename nginx
deb-src http://nginx.org/packages/debian/ codename nginx
EOF

Step 2: Add the signing key.

curl -L https://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Step 3: Update the package sources.

apt update

Step 4: Install or upgrade nginx.

# If nginx is not already installed
apt install nginx

# If nginx is already installed
apt upgrade

For Ubuntu 14.04 LTS, 16.04 LTS, 18.04 LTS, 18.10 and 19.04+

Step 1: Add the source repository.

Be sure to replace codename with the code name for the version of Ubuntu you’re running.

Most likely will work for future versions of Ubuntu past cosmic.

cat <<EOF >> /etc/apt/sources.list.d/nginx.list
deb http://nginx.org/packages/ubuntu/ codename nginx
deb-src http://nginx.org/packages/ubuntu/ codename nginx
EOF

Step 2: Add the signing key.

curl -L https://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Step 3: Update the package sources.

apt update

Step 4: Install or upgrade nginx.

# If nginx is not already installed
apt install nginx

# If nginx is already installed
apt upgrade
Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Born again Linux user. Founder of Holiday API, Backend Engineering Manager and Emoji Specialist at Mailshake (WE'RE HIRING!), and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Pears and Perils
Antifragile: Things That Gain from Disorder
Code Girls: The Untold Story of the American Women Code Breakers of World War II

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles