How to upgrade Ubuntu server to 22.04 LTS

Most of the old servers are either on 16.04 or 18.04. It’s time for you to upgrade. Mine are all on 20.04, even though it is fine to leave it as is for now, but as you know I like to keep up with the latest software and pace of OS. So I decided to upgrade to latest Ubuntu 22.04. In this article I am going to guide you how to upgrade your Ubuntu server to 22.04 LTS.

If you follow this guide and your server has a good Internet connection, the whole process will take around 30 minutes but it could be more or less. Let’s get into it.

Before upgrade

There are few things we need to take care of before jumping to the upgrade process. Make sure your system is up to date.

apt update && apt upgrade

Remove and clean unwanted packages.

apt autoremove && apt autoclean
apt-remove-1

Ubuntu upgrade process need an extra SSH port to be opened in case something goes south. For that we will allow port 1022 in the firewall if UFW is enabled.

ufw status

ufw allow 1022/tcp

ufw reload
ufw-add-port-2
ufw-status-3

Once done if reboot is required, reboot the server.

reboot

After reboot, it’s time to backup your data and databases (if any). Please don’t skip this step and make sure you do take the backup.

We will now stop the running processes like Apache, MariaDB, PHP FPM etc.

You can find the running packages with:

systemctl | grep running

Remember to not stop any critical and system services.

systemctl stop apache2

systemctl stop mariadb
stop-services-4

For PHP FPM (php8.0-fpm is a placeholder, change to yours accordingly) and Redis etc:

systemctl stop php8.0fpm

systemctl stop redis

We are pretty much done with pre upgrade process. Before starting the upgrade, just make sure you are on lts Prompt (Prompt=lts) at the end of the file.

cat /etc/update-manager/release-upgrades
check-lts-mode-5

Upgrade

Now we will start the upgrade process.

do-release-upgrade
do-upgrade-6

This will check your system and proceed with the setup if all checks passed.

upgrade-process-7

From here on most of the prompts are self explanatory, carefully read them and proceed.

Let’s me explain some of them.

At this point you will be shown what are going to be removed, upgraded etc. Press d to get these statistic when shown.

check-packages-deatils-8

You can type y to confirm it.

confirm-to-proceed-9

During the upgrade, you will be asked to either keep your old configurations or use the new one. Keep the old ones as a precaution.

keep-old-configurations-10
keep-ssh-old-config-13

The last step is to remove the obsolete packages.

remove-obsolete-packages-11

Reboot the system when asked.

reboot-12

Post upgrade

after-reboot-14

After successful reboot, we need to perform few quick checks and remove the port added at the beginning.

ufw delete allow 1022/tcp

ufw reload

ufw status

Upgrade and clean the system (not needed though, just for safety).

apt update && apt upgrade && apt autoremove && apt autoclean

And that’s it, enjoy.