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