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

3 minute read
0

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

Resolution

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 24.04, you must first upgrade to version 20.04. Then, upgrade to 22.04, and finally upgrade to 24.04.

Prerequisites: Review the Pre-upgrade checklist on the Ubuntu website. Also, create a backup of your data.

Update your system

Complete the following steps:

  1. To check your operating system (OS) version, run the lsb_release command:

    lsb_release -a

    Example output:

    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 existing LTS Ubuntu version, run the following commands:

    sudo apt update
    sudo apt upgrade
  3. Reboot the server.
    Note: It's a best practice to also reboot the instance after you install the updates to verify that you're running the latest kernel.

Upgrade your LTS Ubuntu version

Complete the following steps:

  1. To upgrade the Ubuntu version, run the do-release-upgrade Ubuntu command:

    sudo do-release-upgrade
  2. Review the upgrades in the summary that you receive, and then press 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]
  3. If there are custom configurations in your existing version that the upgrade might overwrite, then the utility prompts you to confirm the changes. To install the package maintainer's version, press Y. To keep the existing versions, press N. Some scenarios, such as /boot/grub/menu.lst, require you to install the package maintainer's version.
    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] ?
  4. To remove obsolete packages, press Y for the following prompt:

    Searching for obsolete softwareReading state information... Done
    
    Remove obsolete packages? 
    
    73 packages are going to be removed. 
    Continue [yN]  Details [d]
  5. To reboot the system, press Y for the following prompt:

    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: You must reboot the instance to complete the upgrade.

  6. To check your Ubuntu version, run the lsb_release command:

    lsb_release -a

    Example output:

    No LSB modules are available.
    Distributor ID:    Ubuntu
    Description:    Ubuntu 24.04 LTS
    Release:    24.04
    Codename:    focal
AWS OFFICIAL
AWS OFFICIALUpdated a month ago
3 Comments

Should the apt point to Ubuntu's original repositories (http://archive.ubuntu.com/ubuntu, http://security.ubuntu.com/ubuntu), or some AWS-specific mirror?

Thanks

replied 6 months ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied 6 months ago

For point number 6, your example uses the file /etc/ssh/ssh_config.

This file in particular has caused issues for me when doing do-release-upgrade in the past. I forget how I answered, but similarly to this person - https://serverfault.com/questions/996715/ - I was unable to SSH into the EC2 instance afterwards. I had not done any custom changes to ssh_config prior (or since). Are we advised to answer Y to this prompt (install the package maintainer's version)?

replied 5 months ago