Ubuntu

How to Upgrade from Ubuntu 20.04 LTS to Ubuntu 22.04 LTS

Upgrade seamlessly from Ubuntu 20.04 LTS to 22.04 LTS by preparing your system, updating software, and ensuring backups. Follow step-by-step commands to initiate the upgrade process, manage prompts, and reboot into the latest LTS version for improved features and performance.

Canonical released Ubuntu 22.04, also known as Jammy Jellyfish, on April 21, 2022. After Ubuntu 20.04 LTS, this is the most recent long-term support (LTS) release.

Significant improvements, new features, and several new software packages are offered by Ubuntu 22.04, including:

PHP 8.1.2
Python 3.10.4 OpenSSL 3.0 Ruby 3.0
MySQL version 8.0.28
Linux kernel v5.15.0-25 & MESA 22 PostgreSQL 14.2
See the release notes for a detailed list of all the new software packages and features.

We will guide you through the process of upgrading Ubuntu 20.04 to Ubuntu 22.04 in this article.

Requirements
Make sure you fulfill the following prerequisites before starting the upgrade:

20 GB or more of free disk space. The df -Th command can be used to determine the amount of disk space that is available.
Make sure a regular user with sudo rights is set up and has access to the terminal application or SSH. You will use this user to carry out the upgrade procedure.
Additionally, make sure your internet connection is steady and quick. Once the operation has started, don't stop it.
Make sure your battery or UPS is operational and properly charged.
Shut off every open application.

Step 1: Make a complete data backup.
Before starting any significant operating system upgrade, it is wise to create a backup of all your databases and files. In the event that something goes wrong during the upgrading process, this guarantees that you won't lose your data.

Snapshot services are provided by cloud server providers. In order to restore your instance in the event that it malfunctions, make sure you take a complete snapshot if you are using a virtual machine or cloud VPS.

 

Step 2: Update every package in the system
Upgrade all of the packages to the most recent versions after logging into your instance and setting up the backup. This updates the system to the most recent version of Ubuntu.
perform the following command to see a list of upgradeable packages (note: to obtain the most recent information, you might want to perform the sudo apt update command first if you haven't done this in a while):

$ sudo apt list –upgradable

Then, use a single command to upgrade the packages and refresh the local package index as follows:

$ sudo apt update && sudo apt upgrade -y

Depending on how many installed packages have outstanding upgrades, this could take some time. To benefit from the most recent kernel included with the upgrade, restart your computer after it is finished.

 

$ sudo reboot

After that, log back in and make that the system has been updated to the most recent version, which is Ubuntu 20.04.4 LTS as of the time this post was published.

Step 3: Allow access to TCP port 1022
If you are using SSH to connect to your Ubuntu instance, the upgrade tool will open port 1022 as a backup port in case port 22's SSH connection fails.

We advise you to open port 1022 on your firewall in the following manner to make things easier. To make sure you are reducing any security threats, we also advise consulting with your networking staff in advance. When you're finished, make sure to close the port by following Step 6 below.

$ sudo ufw allow 1022/tcp

To apply the firewall rule, reload the firewall.

$ sudo ufw reload

Then verify that the port has been opened by probing the firewall status as shown.

$ sudo ufw status

Upgrade to Ubuntu 22.04 in step four. Jellyfish Jammy
By now, the process of updating to Ubuntu 22.04 will be simple and smooth. To update to the most recent version of Ubuntu, you can use either the GUI update tool or the do-release-upgrade tool, which is compatible with both CLI and GUI instances.

We will make use of the do-release-upgrade utility in this guide. If it's not installed, use the following command to install it:

$ sudo apt install update-manager-core

To commence the upgrade, run the command:

$ sudo do-release-upgrade

The upgrade tool will search for the most recent LTS release and guide you through a number of prompts while you're upgrading.

It will first identify your SSH connection and alert you when a new SSH service on port 1022 is about to be launched. Just type "Y" to continue.


The update program will then alert you to open port 1022, which will serve as a backup SSH port in the event that the default port's SSH connection is lost. Simply press ENTER since you have already opened the port.

Next, you will be prompted to update the “sources.list” file from ‘focal’ to ‘jammy’ entries. To proceed with the upgrade, press “Y” and press ENTER.

 The following will be summarized by the update tool when all the changes have been calculated:

1. installed packages that Canonical no longer supports.
2. how many packages need to be taken out.
3. how many additional packages will be installed.
4. how many packages will receive upgrades.
5. The size of the entire download and its estimated duration.
6. Press "Y" and ENTER once again to proceed.

Some services will need to be restarted once some libraries and packages are upgraded. On this pop-up, select ‘Yes‘ to restart these services during package upgrades without being prompted.

From here, the upgrade tool will proceed to download all the requisite packages from the official Ubuntu repositories and upgrade them.

 

When prompted on what to do with the modified “sshd_config” configuration file, you can choose to install the package maintainer’s version or keep the local version installed. Then, select ‘Ok’.

Next, press “Y” and hit ENTER to remove obsolete packages.

Thereafter, all the old packages alongside their configuration files will be removed.

Patience will be needed because the entire process takes a long time. Now would be a wonderful time to stop and get a cup of coffee.

To complete the upgrade, you will be need to restart the system after it is finished. To restart, press "Y" and then ENTER. You will lose your connection to the server as a result.

Step 5: Confirm that Ubuntu 22.04 has been upgraded.
Log in again after rebooting to make sure the upgrade went through.

While the program uname -mrs checks the kernel version, the command lsb_release -a checks the Linux version.

We are now running Ubuntu 22.04 LTS, as you can see from the output below. Additionally, take note that we are utilizing kernel 5.15, which is the default kernel version included with Ubuntu 22.04.

Step 6: Delete the firewall rule you made After the update is complete and port 1022 is no longer required open, use the command below to close the port and stop it from becoming a security flaw.

ufw delete allow 1022/tcp

Step 7: Enable third-party repositories

During the upgrade, all third-party repositories are disabled. You might want to re-enable them now that the upgrade is complete. You can find these repositories in the/etc/apt/sources.list.ddirectory. 

To display these repositories, run the command:

 $ ls -l etc/apt/sources.list.d/

To enable them, simply open each file and uncomment the entries by deleting the # sign at the beginning of each line.

Finally, free up the disk space by removing all the unnecessary packages as follows:

$ sudo apt autoremove –purge

In conclusion
As you can see, updating Ubuntu 20.04 to Ubuntu 22.04 only takes a few commands and is a straightforward procedure.

Your routine can quickly become convoluted if you are an IT administrator managing updates for several Ubuntu systems in addition to macOS and Windows devices.