Sling Academy
Home/DevOps/How to upgrade Ubuntu to a newer version

How to upgrade Ubuntu to a newer version

Last updated: January 28, 2024

Introduction

Upgrading an operating system can sometimes be a daunting task but keeping your system up to date is crucial for security and access to the latest features. In this tutorial, we will go through the steps required to upgrade Ubuntu to a newer version. We will start with simple commands and explore different scenarios to ensure you can competently manage your Ubuntu upgrade.

Prerequisites

  • A working Ubuntu system with access to the internet
  • A user account with sudo or root privileges
  • Backup of important data

Step-by-Step Instructions

Step 1: Preparing the System

Before upgrading Ubuntu, it is important to update the current system with the latest packages. Use the following commands to update all installed packages.

sudo apt update
sudo apt upgrade

After the updates and upgrades are installed, it is always a good practice to remove unnecessary packages and clean the system.

sudo apt autoremove
sudo apt autoclean

Step 2: Installing the Update Manager

If you do not have the update-manager-core package installed, do so with the following command:

sudo apt install update-manager-core

Step 3: Configuring the System for Upgrade

Edit the /etc/update-manager/release-upgrades file to define how the system notifies you of new releases.

sudo nano /etc/update-manager/release-upgrades

In this file, find the Prompt line and configure it to either normal for regular releases, or lts for Long-Term Support (LTS) releases.

Step 4: Begin the Upgrade Process

To start the upgrade process, you can use the do-release-upgrade command.

sudo do-release-upgrade

Follow the on-screen instructions. The system will prompt you to confirm the upgrade and may ask you about a series of package upgrades or services restarts.

Handling Possible Issues

Network Upgrade for Servers

If you are upgrading a headless server, you can use the -d flag to perform a network upgrade:

sudo do-release-upgrade -d

The -d option will also work for desktop versions, especially if the intention is to upgrade before the updated packages have made their way to all mirrors.

Upgrading Without a Connection

For systems without a direct internet connection, you can use the following command with the appropriate Media or ISO:

do-release-upgrade -f DistUpgradeViewNonInteractive -m https://path/to/media/or/iso

Partial Upgrades

If notified of a ‘partial upgrade’, you can deal with it by using the following:

sudo apt --fix-broken install

This command will try to correct a system with broken dependencies in place.

Advanced Upgrading Scenarios

Upgrading Using the Command Line

Edit the /etc/apt/sources.list file to change the source URLs from the current version to the new version:

sudo sed -i 's/old-version/new-version/g' /etc/apt/sources.list

Then update and begin the dist-upgrade:

sudo apt update
sudo apt dist-upgrade

Reverting Back to the Original Version

In case you need to revert your system back to its original state before the upgrade, you can try to ppa-purge the PPAs:

sudo apt install ppa-purge
sudo ppa-purge ppa:repository/name

Or use Timeshift or a similar tool to restore the system to a previous snapshot.

Conclusion

The process of upgrading Ubuntu can be lengthy but it can be smoothed out if the steps outlined are closely followed. Always ensure that your data is backed up before commencing an upgrade and schedule enough time to address any arising issues.

Next Article: How to reset Ubuntu to factory settings (4 approaches)

Series: Linux Tutorials

DevOps

You May Also Like

  • How to reset Ubuntu to factory settings (4 approaches)
  • Making GET requests with cURL: A practical guide (with examples)
  • Git: What is .DS_Store and should you ignore it?
  • NGINX underscores_in_headers: Explained with examples
  • How to use Jenkins CI with private GitHub repositories
  • Terraform: Understanding State and State Files (with Examples)
  • SHA1, SHA256, and SHA512 in Terraform: A Practical Guide
  • CSRF Protection in Jenkins: An In-depth Guide (with examples)
  • Terraform: How to Merge 2 Maps
  • Terraform: How to extract filename/extension from a path
  • JSON encoding/decoding in Terraform: Explained with examples
  • Sorting Lists in Terraform: A Practical Guide
  • Terraform: How to trigger a Lambda function on resource creation
  • How to use Terraform templates
  • Understanding terraform_remote_state data source: Explained with examples
  • Jenkins Authorization: A Practical Guide (with examples)
  • Solving Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap
  • Understanding Artifacts in Jenkins: A Practical Guide (with examples)
  • Using Jenkins with AWS EC2 and S3: A Practical Guide