Skip to content

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

4 minute read
0

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

Short description

You can upgrade the LTS Ubuntu version of your EC2 instance 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.

Resolution

Prerequisites:

Update your system

Complete the following steps:

  1. To check your operating system (OS) version, run the following 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 run the latest kernel.

Upgrade your LTS Ubuntu version

Complete the following steps:

  1. To upgrade the Ubuntu version, run the following Ubuntu command:

    sudo do-release-upgrade

    Note: You can upgrade to the next LTS Ubuntu version release only after the first point release of the latest LTS version. For example, to upgrade Ubuntu 18.04 LTS to 20.04 LTS, Ubuntu must release 20.04.1. To test or evaluate an upgrade earlier than the point release, add the -d flag to the preceding command to upgrade to a development release of Ubuntu. Don't use the -d flag for production environments. Development releases aren't fully tested or supported. For a list of releases and support status, see List of releases on the Ubuntu website.

  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. It's a best practice to use the default selection. To keep the existing versions, press N. To install the package maintainer's version, press Y. Some scenarios, such as /boot/grub/menu.lst, require you to install the package maintainer's version. To view the differences in the file versions, press D.
    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 software
    Reading 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]
  6. Reboot the instance to complete the upgrade.

  7. To check your Ubuntu version, rerun the following 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 OFFICIALUpdated a month ago
4 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 a year ago

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

AWS
MODERATOR
replied a year 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 a year ago

question: we have an Ubuntu instance in AWS. We want to upgrade it from 18 LTS to 20 LTS. Is there any pre-requisite of what type of Ubuntu that currently installed in server to have successfully upgrade it to 20 LTS? like, its must be... Ubuntu Pro? or our Ubuntu must be in esm-infra? I tried the first 2 command, and run the update-manager-core and it says "update-manager-core is already the newest version (1:18.04.13.1)"

Why and how should I resolve this?

replied 3 months ago