We previously wrote an article on How to Upgrade NGINX to the Latest Stable Version on Ubuntu. With the release of Ubuntu 20.04 LTS, server administrators are going to start getting prompted to to upgrade from Ubuntu 18.04 LTS to Ubuntu 20.04 LTS. If you previously had NGINX installed in Ubuntu 18.04 LTS, it will continue to work after upgrading to Ubuntu 20.04 LTS, but you’ll have difficulties upgrading it.
If you previously had NGINX installed for Ubuntu 18.04 Bionic, you’ll need to uninstall it before you can upgrade to the version of NGINX for Ubuntu 20.04 Focal. You’ll get some errors if you’re using APT to upgrade.
Backup your /etc/nginx folder first. Either make a copy on the server or use SFTP to download a copy. The directory shouldn’t be removed during the uninstall/reinstall, but it is always good to make a copy first.
Remove Old Versions of NGINX
Run this command to uninstall the previous versions of nginx:
sudo apt remove nginx nginx-common nginx-full nginx-core
Install the Prerequisites
sudo apt install curl gnupg2 ca-certificates lsb-release
Setup the APT Repo and Import Signing Key
You can install from either the stable branch or mainline branch. Mainline is considered development, but it has the latest features. The Stable branch will only receive security fixes. NGINX themselves recommends that you use the mainline branch.
To set up the apt repository for stable nginx packages, run the following command:
echo "deb http://nginx.org/packages/ubuntu `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 http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list
Next, import an official nginx signing key so apt could verify the packages authenticity:
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
Verify that you now have the proper key:
sudo apt-key fingerprint ABF5BD827BD9BF62
The output should contain the full fingerprint 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62.
To install nginx, run the following commands:
sudo apt update
sudo apt install nginx
Start and Enable NGINX
To start the nginx service and enable it after reboots, run these commands:
sudo systemctl start nginx
sudo systemctl enable nginx
You can check the currently running version by running
Once you have upgraded NGINX on Ubuntu 20.04 LTS, you can check your sites and your config files. As long as you selected the default options during the installation, it should have kept your previous configs. Otherwise, it is best practice to go through your backup configs and add to the default rather than copying over the new configs.