How do I upgrade Ubuntu on my EC2 Linux instance from one LTS version to another?

3 minute read

I want to upgrade the long term support (LTS) Ubuntu version on my Amazon Elastic Compute Cloud (Amazon EC2) instance.


Note: You can upgrade the LTS Ubuntu version only to the next sequential version. For example, to upgrade from LTS Ubuntu version 18.04 to version 22.04, you must first upgrade to version 20.04. Then, you can upgrade to 22.04.


Upgrade the LTS Ubuntu version

1.    To verify the current release, run the lsb_release command:

$ lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:    20.04
Codename:    focal

2.    To install all the available updates for your LTS version, run the following commands:

$ sudo apt update
$ sudo apt upgrade

Note: Make sure that the commands complete their action and that no further updates are available.

3.    Reboot the server.

Note:  It's a best practice to reboot the instance after the updates install to verify that the latest kernel is running.

4.    Ubuntu uses the do-release-upgrade command in Debian-based Linux distributions. Run this command to upgrade from one version of Ubuntu to another:

$ sudo do-release-upgrade

5.    The do-release-upgrade command performs checks to verify that the system is ready to update. You're prompted with a summary of the upgrade. Review the changes, and then enter y.

Example upgrade summary:

Do you want to start the upgrade? 

3 packages are going to be removed. 90 new packages are going to be 
installed. 567 packages are going to be upgraded. 

You have to download a total of 356 M. This download will take about 
1 minute with your connection. 

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

 Continue [yN]  Details [d]

6.    If there are custom configurations in your existing version that the update might overwrite, then the utility prompts you to confirm the changes.

Example prompt:

Configuration file '/etc/ssh/ssh_config'
 ==> 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.
*** ssh_config (Y/I/N/O/D/Z) [default=N] ?

Note: The default response N keeps the current version of the file. There are scenarios, such as /boot/grub/menu.lst, that require you to install the package maintainer's version so that the system correctly boots with the new kernel.

7.    In the prompt to remove obsolete packages, enter y:

Searching for obsolete software
Reading state information... Done

Remove obsolete packages? 

73 packages are going to be removed. 
Continue [yN]  Details [d]

8.    In the prompt to reboot the system, enter y:

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]

Note: The upgrade isn't complete until you reboot the instance.

9.    To verify the LTS Ubuntu version, run the lsb_release command:

lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:    22.04
Codename:    jammy
AWS OFFICIALUpdated 5 months ago