How to upgrade Ubuntu 20.04 to 22.04

Make sure you have at least 30 GB of free space on your hard disk. You can run the following command to know about the free space:

df -h

For details on how to get the size of hard disk you can following this blog: How to check the hard disk size in ubuntu

If you don’t have the enough free space then you can following the following blog for increasing hard disk on EC2 instance: How to increase hard disk size of Ubuntu EC2 Instance

Check the existing version of your Ubuntu, it should be 20.04

 lsb_release -a

Output:

Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.4 LTS
Release:	20.04
Codename:	focal

Run sudo apt update command:

sudo apt update

Run sudo apt upgrade command:

sudo apt upgrade

Reboot the machine:

sudo reboot

Time to run the final command to the upgrade from Ubuntu 20.04 to 22.04

sudo do-release-upgrade

Output:

Fetching and installing the upgrade can take several hours. Once the 
download has finished, the process cannot be canceled. 

Select “yes” in the Package configuration modal.

Configuration file ‘/etc/nginx/nginx.conf’
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer’s version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** nginx.conf (Y/I/N/O/D/Z) [default=N] ?

After installing all the features, it will prompt you to restart the machine:


System upgrade is complete.

Restart required 

To finish the upgrade, a restart is required. 
If you select 'y' the system will be restarted. 

Continue [yN] 

Enter “y” to restart the machine.

Run the  lsb_release -a command again after restart to check the Ubuntu version:

lsb_release -a

The output will be like this:

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.1 LTS
Release:	22.04
Codename:	jammy

You are done with upgrade of Amazon EC2 Ubuntu 20.04 LTS to 22.04 LTS.