Upgrade Ubuntu 20.04 to Ubuntu 22.04
Ubuntu is a modern open-source Linux distribution that is available in multiple releases. Ubuntu 22.04 is an LTS (Long Term Support) version that comes with updated packages, newer kernel features, enhanced stability for applications, and improved security compared to Ubuntu 20.04. Upgrading from Ubuntu 20.04 to 22.04 allows you to benefit from these advancements.
This guide explains how to upgrade your system from Ubuntu 20.04 to Ubuntu 22.04.
Prerequisites
Before you begin, make sure that you meet the following requirements:
- An Ubuntu 20.04 server instance.
- Access to the server via SSH as a non-root user with sudo privileges.
- At least 5GB of available disk space.
Check your available disk space with:
$ df -h
Example output:
Filesystem Size Used Avail Use% Mounted on tmpfs 96M 2.4M 93M 3% /run /dev/vda2 23G 6.5G 16G 30% / tmpfs 476M 0 476M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/vda1 511M 6.1M 505M 2% /boot/efi tmpfs 96M 4.0K 96M 1% /run/user/0
Check Application Compatibility
Before upgrading, ensure that installed applications are compatible with Ubuntu 22.04. Incompatible applications could lead to runtime errors or package conflicts.
Export the list of installed packages to a file:
$ sudo dpkg --get-selections > packages-list.txt
View the exported file contents:
$ cat packages-list.txt | more
Review the official Ubuntu 22.04 release notes to confirm compatibility and check for known issues.
Prepare the Server for Upgrade
Update your system and upgrade existing packages before proceeding with the release upgrade.
Check your current version:
$ cat /etc/os-release
Update package lists:
$ sudo apt update
Upgrade installed packages:
$ sudo apt upgrade -y
If you encounter a kernel warning about a newer version being available, reboot the server:
$ sudo reboot
Remove unnecessary packages and cached files:
$ sudo apt autoremove -y
$ sudo apt autoclean
Enable Temporary SSH Port
The upgrade process may use port 1022 as a fallback. Configure your firewall to allow it:
$ sudo ufw allow 1022/tcp
Reload UFW:
$ sudo ufw reload
Check status:
$ sudo ufw status
Example output shows port 22 and port 1022 allowed.
Upgrade From Ubuntu 20.04 to 22.04
Start the upgrade with the following command:
$ sudo do-release-upgrade
Follow the prompts to confirm the upgrade, enable port 1022, apply firewall rules, select your keyboard layout, and handle configuration file prompts (choose to keep your current versions unless you have specific needs).
During the upgrade process, obsolete packages will be listed. Confirm their removal when prompted.
Once the upgrade completes, restart your server when asked:
System upgrade is complete. Restart required
Post-Upgrade Step
After the upgrade, consider installing Docker on Ubuntu 22.04. Docker enables containerized application management, improving efficiency and resource utilization.
Test the Upgraded Ubuntu 22.04 Server
Follow these steps to confirm that your system has successfully upgraded to Ubuntu 22.04 and that server packages are working as expected.
Check the current Ubuntu version:
$ cat /etc/os-release
Example output:
PRETTY_NAME="Ubuntu 22.04.5 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.5 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy
Check the kernel version to confirm it is updated:
$ uname -mrs
Example output:
Linux 5.15.0-136-generic x86_64
Remove the temporary SSH port 1022 rule you previously enabled:
$ sudo ufw delete allow 1022/tcp
Resolve Post-upgrade Issues
After the upgrade, make sure that your APT repositories and installed packages are updated correctly.
List the APT configuration directory contents:
$ ls /etc/apt/
Update any third-party repository definitions to reference Ubuntu 22.04 sources.
Update your package index:
$ sudo apt update
Upgrade all packages to their latest versions:
$ sudo apt upgrade
Remove obsolete and unused packages:
$ sudo apt autoremove -y && sudo apt autoclean
Conclusion
You have successfully upgraded your server from Ubuntu 20.04 to Ubuntu 22.04. With this upgrade, your system benefits from enhanced security, improved performance for applications, and updated package dependencies. For further details about the upgrade process, consult the official Ubuntu server upgrade documentation.


