How to Upgrade Ubuntu 18.04 to 20.04 and 20.04 to 22.04
Ubuntu 18.04 left standard support in May 2023 and 20.04 in May 2025. Both still get security fixes only through Ubuntu Pro (ESM). 22.04 is supported until 2027, so if you are upgrading old machines now, plan to keep going to 24.04 and possibly 26.04, one LTS step at a time.
The procedure is the same for every LTS hop. This post covers it once, then lists what changes in each step.
You cannot skip releases
do-release-upgrade moves you to the next LTS only. From 18.04 the path is 18.04 → 20.04 → 22.04 → 24.04 → 26.04, with a reboot and a check after each step.
If a machine is several releases behind and its setup lives in Ansible, Terraform or a Dockerfile, rebuilding it on a current release is often faster and cleaner than four in-place upgrades. In-place upgrades make sense for machines that were configured by hand and are hard to recreate.
Before you start
Take a backup you can restore. On a VM or cloud instance, a snapshot right before the upgrade is the simplest rollback. On bare metal, back up /etc, application data and databases (with a proper dump, not a copy of a running data directory).
Bring the current release fully up to date. The upgrader refuses to run otherwise.
sudo apt update
sudo apt full-upgrade
sudo apt autoremove --purge
sudo reboot
Check free space. A release upgrade downloads and unpacks a lot of packages. Have a few GB free on / and enough room on /boot for an extra kernel.
df -h / /boot
Review third-party repositories and PPAs. The upgrader disables them during the upgrade. Software from them (PHP from a PPA, Docker, database vendor repos) may need a different repository line or version on the new release. Check that the vendor supports the target release first.
ls /etc/apt/sources.list.d/
apt list --installed 2>/dev/null | grep ',local\]' # installed packages no repository provides
Check the upgrade prompt setting. /etc/update-manager/release-upgrades should contain Prompt=lts (the default on servers). With Prompt=never the upgrader finds nothing.
Run the upgrade
sudo apt install update-manager-core
sudo do-release-upgrade
Things to know while it runs:
- Over SSH, it warns you and starts a second SSH daemon on port 1022 as a fallback. If you use a firewall, open that port temporarily (
sudo ufw allow 1022/tcp) before you continue. - It runs inside
screenwhenscreenis installed, so a dropped connection does not kill it. Reconnect and attach withsudo screen -r. - It asks before replacing configuration files you changed (
sshd_config,nginx.conf, PHP ini files). The safe default is to keep your version (N) and compare with the new package version (.dpkg-distfile) afterward. - It asks whether to remove obsolete packages near the end. Read the list. Packages you installed by hand from removed repositories can show up here.
- Do not use
-d. It upgrades to the development release.
Reboot when it finishes, then verify:
lsb_release -a
uname -r
systemctl --failed
After the upgrade
Re-enable third-party repositories. The upgrader comments them out with a note such as # disabled on upgrade to jammy. Edit each one for the new codename (focal, jammy, noble) and check the vendor's instructions, then run sudo apt update.
Clean up:
sudo apt autoremove --purge
Check your applications, not just the OS: start services, read their logs with journalctl -u name -b, and run whatever health checks you have.
What changes from 18.04 to 20.04
- Python 2 is gone from the default install, and there is no
pythoncommand. Scripts with#!/usr/bin/env pythonbreak. Fix the scripts to usepython3, or installpython-is-python3as a stopgap. - MySQL 5.7 → 8.0. The data directory is upgraded in place and cannot be downgraded. Dump your databases before the upgrade. Check for removed SQL modes and authentication changes in your apps.
- PHP 7.2 → 7.4, PostgreSQL 10 → 12, kernel 4.15 → 5.4.
What changes from 20.04 to 22.04
- OpenSSH 8.9 disables the old
ssh-rsa(RSA with SHA-1) signature algorithm by default. RSA keys still work with SHA-2 signatures, but very old clients, network devices and libraries that only speak SHA-1 can no longer connect. - OpenSSL 3.0 replaces 1.1.1. Some legacy algorithms and weak certificates are rejected, and software built against OpenSSL 1.1 needs packages for 22.04.
- cgroup v2 only by default. Old Docker releases and older Kubernetes components that only understand cgroup v1 fail to start containers.
- PHP 7.4 → 8.1, Python 3.8 → 3.10, PostgreSQL 12 → 14, kernel 5.4 → 5.15.
PostgreSQL clusters stay on the old version
A release upgrade does not migrate your database. The old cluster keeps running on the old PostgreSQL packages, which are now unsupported. Upgrade the cluster explicitly:
pg_lsclusters
sudo pg_dropcluster 14 main --stop # only if the new, empty 14 cluster was created
sudo pg_upgradecluster 12 main
pg_lsclusters # check the new cluster, then drop the old one
Do this on 18.04 → 20.04 as well (10 → 12).
When the upgrade stops halfway
A failure during package configuration leaves a mix of old and new packages. Do not reboot in that state if you can avoid it. Finish the package work first:
sudo dpkg --configure -a
sudo apt -f install
sudo apt full-upgrade
Then run do-release-upgrade again if it says the upgrade is incomplete. If the system no longer boots, restore the snapshot. That is what it is for.
Staying on an old release
If you cannot upgrade yet, enable Ubuntu Pro to keep getting security fixes for 18.04 or 20.04. It is free for personal use on up to five machines.
sudo pro attach <token>
pro status
That buys time, not a plan. Applications and their dependencies on those releases are still old.
Going further: 22.04 to 24.04 and 26.04
The same steps apply. LTS-to-LTS upgrades are offered once the first point release of the new LTS is out (24.04.1, 26.04.1). From 22.04 to 24.04, the upgrader also moves APT sources to the deb822 format in /etc/apt/sources.list.d/ubuntu.sources.
Quick reference
sudo apt update && sudo apt full-upgrade && sudo reboot # current release up to date
df -h / /boot # free space
grep Prompt /etc/update-manager/release-upgrades # must be lts
sudo ufw allow 1022/tcp # fallback ssh during upgrade
sudo do-release-upgrade # one LTS step
lsb_release -a && systemctl --failed # verify after reboot
sudo dpkg --configure -a && sudo apt -f install # recover an interrupted upgrade
sudo pg_upgradecluster OLD main # migrate PostgreSQL afterward
