Member-only story
Upgrading Nginx from version 1.18 to 1.25 (Ubuntu 20.04)
Introduction
This article outlines the step-by-step process of upgrading Nginx from version 1.18 to 1.25 on an Ubuntu 20.04 server, highlighting the intricacies and considerations involved in such a task.
The Challenge
Nginx, a popular web server known for its performance and flexibility, often releases updates that introduce new features, security patches, and performance improvements. For a system administrator, keeping Nginx up-to-date is essential. However, this task can be challenging, especially when the required version is not available in the standard Ubuntu repositories. This was the case with Nginx 1.25, which at the time of the upgrade was only available in the mainline repository.
Upgrading Nginx from version 1.18 to 1.25 on an Ubuntu 20.04 server involves several steps. You need to add the Nginx mainline repository to your system, update the package list, and then perform the upgrade. Here’s a step-by-step guide:
Step 1: Backup Configuration Files:
Before making any changes, it’s always a good practice to backup existing configuration files. You can do this by copying the /etc/nginx
directory.
sudo cp -r /etc/nginx /etc/nginx-backup
Step 2: Add Nginx Mainline Repository:
Since Nginx 1.25 is available in the mainline repository, you need to add this repository to your system.
➤ Option 2: Use signed-by to import Nginx repository key — RECOMMENDED
# Download and save the key to a trusted location
curl -fsSL https://nginx.org/keys/nginx_signing.key \
| gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg
# Add the Nginx mainline repository using the keyring
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu $(lsb_release -cs) nginx" | \
tee /etc/apt/sources.list.d/nginx.list
➤ Option 2: Alternatively, using apt-key to import repository key — DEPRECATED!!! in later versions of Ubuntu
# import and add repository key using apt-key - deprecated!!!
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
echo "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list