Skip to main content

How to Upgrade to the Latest Version of Ubuntu

 

We’ve started a new DevOps area on the site. If you’re interested in writing about DevOps, check out the Contribution Guidelines.

1. Overview

Ubuntu is a Debian-based, open-source Linux distribution made for desktops, cloud computing, the Internet of Things (IoT), and enterprise servers, i.e., servers that collectively satisfy the requirements of an enterprise or a company instead of a single user.

As Ubuntu users, we can optimize the Linux flavor in many ways to help it reach its full potential. One such way is upgrading to the newest available version on the Internet.

In this tutorial, we’ll discuss a step-by-step process to upgrade Ubuntu to the latest version.

2. Optimize Package List

The first step in the process is to optimize the package list on Ubuntu.

Firstly, we update the package list on the distribution:

$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
Get:7 http://security.ubuntu.com/ubuntu focal-security/main Translation-en
Get:8 http://security.ubuntu.com/ubuntu focal-security amd64 Contents (deb)
Get:9 http://archive.ubuntu.com/ubuntu focal-updates/main Translation-en
Get:10 http://archive.ubuntu.com/ubuntu focal-updates amd64 Contents (deb)
Fetched 444 MB in 7min 30s (988 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
6 packages can be upgraded. Run 'apt list --upgradable' to see them.

The apt command works as a package manager on Ubuntu and other Debian-based distros. When we combine it with the update subcommand, it updates the package list on the current installation with the latest available versions and gives us a list of upgradable packages. Moreover, as we need to be a root user to perform this operation, we’ve used the sudo command.

As we can see, six packages can be upgraded in this case.

So, let’s upgrade them using the apt upgrade command:

$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  libc-bin libc-dev-bin libc6 libc6-dev libx11-6 libx11-data
6 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
5 standard LTS security updates
Need to get 12.2 MB of archives.
After this operation, 102 kB of additional disk space will be used.
Do you want to continue? [Y/n] yes

We provide yes as an input into the terminal when prompted to continue with the package upgrade process.

After the process is complete, we use the autoremove command to remove all the unnecessary packages from the distro and also utilize the –purge option to remove all of their configuration files too:

$ sudo apt autoremove --purge
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  linux-image-4.15.0-45-generic* linux-headers-4.15.0-45*
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 124 MB disk space will be freed.
Do you want to continue? [Y/n] yes
(Reading database ... 140963 files and directories currently installed.)
Removing linux-image-4.15.0-45-generic (4.15.0-45.48) ...
Removing linux-headers-4.15.0-45 (4.15.0-45.48) ...

Again, we’ve entered yes as an input to the prompt to continue the removal procedure.

The package list is now optimized. Hence, it’s time to proceed to the next step.

3. Install update-manager-core

The update-manager-core package is essential for upgrading Ubuntu from one version to another.

Before installing the package, we reboot the distribution to ensure that it’s working fine:

$ sudo reboot

Then, we install the package:

$ sudo apt install update-manager-core

Once the installation is complete, we can move on to the upgrade itself.

4. Upgrade Ubuntu to the Latest Version

We’ve already optimized the package list in Ubuntu, which helps prevent problems during the upgrade process. Moreover, we’ve installed the update-manager-core package, enabling us to upgrade Ubuntu.

Now, let’s learn how to install the latest version of Ubuntu.

4.1. Initiating the Version Upgrade Process

First, we obtain the newest version of Ubuntu that’s available on the Internet:

$ sudo do-release-upgrade -c
Checking for a new Ubuntu release
New release '23.04' available.

The do-release-upgrade command upgrades a distribution to the latest version. However, the -c option, short for –check-dist-upgrades, tells the command to only check for the newest available version of Ubuntu.

Evidently, the latest version is 23.04. So, let’s upgrade the distro to this version using the above command with no options:

$ sudo do-release-upgrade
Checking for a new Ubuntu release
Get:1 Upgrade tool signature [813 B]
Get:2 Upgrade tool [1,266 kB]
Fetched 1,267 kB in 0s (0 B/s)
authenticate 'lunar.tar.gz' against 'lunar.tar.gz.gpg’
extracting 'lunar.tar.gz’

Reading cache

Checking package manager
Reading package lists... Done
Building dependency tree
Reading state information... Done

Visibly, we’ve successfully initiated the operation.

4.2. Navigating Through the Process

During the operation, we encounter back-to-back prompts that we have to answer correctly to proceed to the next step and eventually finish the upgrade process.

The first prompt asks for permission to start upgrading Ubuntu. Here, we hit Enter to give permission and start the upgrade process:

Do you want to start the upgrade?

Then, we see some information regarding the upgrade and a prompt that urges us to verify the information. In this case, we type yes in the terminal to validate the information and proceed to the next step:

4 packages are going to be removed. 90 new packages are going to be
installed. 564 packages are going to be upgraded.

You have to download a total of 565 M. This download will take about
1 minute with a 40Mbit connection and about 15 minutes with a 5Mbit
connection.

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

 Continue [yN] Details [d] yes

The next prompt seeks permission to remove outdated packages from the distro. Here, we again type yes to give permission and move on to the final step:

Searching for obsolete software
Reading state information... Done

Remove obsolete packages?


80 packages are going to be removed.

 Continue [yN] Details [d] yes

The final prompt asks us to restart the system to finish the upgrade process. In this case, we input yes for the last time in the terminal to proceed:

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] yes

Now, we’ve finished upgrading Ubuntu. Let’s see how to verify the Ubuntu upgrade.

5. Verify Version Upgrade

We can verify if we have the latest version of Ubuntu, i.e., 23.04, by running a single command in the terminal:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 23.04
Release:        23.04
Codename:       lunar

The lsb_release command prints information about the Linux Standard Base (LSB). However, the -a option, short for –all, tells the command to display information regarding the distro, which contains its distributor ID, description, release number, and codename.

The Release label shows the release number, i.e., the current version of Ubuntu, which is 23.04 in this case. This indicates that we’ve upgraded to the latest version of Ubuntu.

6. Enable Third-Party Repositories

When we upgrade Ubuntu, all third-party repositories are disabled, which can cause problems when operating on the upgraded Ubuntu version. Therefore, we can enable them after the upgrade to keep the distro running smoothly.

However, if enabling third-party repositories causes problems, we can fix this by disabling them again.

Now, let’s go through the process of enabling a disabled repo.

6.1. Finding Disabled Repos

First, we find the third-party repos that are disabled on Ubuntu. To do that, we navigate to the sources.list.d directory located in /etc/apt:

$ cd /etc/apt/sources.list.d

Then, let’s list the contents of /etc/apt/sources.list.d:

$ ls -l
-rw-r--r-- 1 root root 132 May 22 04:48 ansible-ubuntu-ansible-focal.list
-rw-r--r-- 1 root root 190 May 22 04:48 google-chrome.list
-rw-r--r-- 1 root root 190 May 22 04:48 google-chrome.list.save

The -l option restricts each line to contain only a single entry.

Evidently, there are some disabled repos in the directory that we can enable one by one.

6.2. Enabling a Disabled Repo

Let’s see how to enable a disabled repository by enabling the google-chrome.list repo, which provides Google Chrome on Ubuntu.

So, let’s open the repo or file in the nano editor:

$ sudo nano google-chrome.list

Upon opening the file, we see its contents in the terminal:

# deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main

The hash (#) symbol indicates the line after it’s commented out, making Google Chrome disabled on the distro. To enable it, we remove the hash:

deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main

After modifying, we press Ctrl + x to quit the editor and then hit y to save the file. The Google Chrome repository is enabled upon saving, and all future updates are now available.

Now, we can follow this process for every repo in the directory to enable all of them on Ubuntu.

7. Software From Unsupported Ubuntu Releases

Upgrading software from an old and unsupported Ubuntu release can provide access to new features. Additionally, upgrading software enables us to apply critical security patches that can protect the systems from cyberattacks.

Additionally, some tools may have dependencies that are only available in older or unsupported Ubuntu releases.

Therefore, let’s explore how to install or upgrade software from the old and unsupported Ubuntu releases. In summary, the procedure involves changing the repositories and reflecting that change internally within the operating system.

7.1. Installing Software

To install software from an old and unsupported Ubuntu release, first, we edit the /etc/apt/sources.list file. The source.list file contains the software sources the package management system uses to install software packages.

Therefore, we open the source.list file using an editor like nano:

$ sudo nano /etc/apt/sources.list
# deb http://archive.ubuntu.com/ubuntu/ jammy main restricted

# deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb http://archive.ubuntu.com/ubuntu/ jammy-security main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
...output truncated...

Now, we replace the archive.ubuntu.com repository with the old-releases.ubuntu.com repository in the source file. We can achieve this task either by editing the source file manually or running a command from the terminal:

$ sudo sed -i -re 's/([a-z]{2}\.)?archive.ubuntu.com|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

Let’s take a look at the updated source file:

$ sudo nano /etc/apt/sources.list
# deb http://old-releases.ubuntu.com/ubuntu/ jammy main restricted

# deb http://old-releases.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb http://old-releases.ubuntu.com/ubuntu jammy-security main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://old-releases.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://old-releases.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://old-releases.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://old-releases.ubuntu.com/ubuntu/ jammy-updates main restricted
...output truncated...

Moreover, after updating the source file, let’s update the package lists:

$ sudo apt-get update
[sudo] password for sam: 
Hit:1 http://repo.linuxliteos.com/linuxlite fluorite InRelease                 
Hit:2 http://archive.canonical.com/ubuntu jammy InRelease                      
Ign:3 http://old-releases.ubuntu.com/ubuntu jammy InRelease                    
Ign:4 http://old-releases.ubuntu.com/ubuntu jammy-updates InRelease            
Hit:5 https://dl.google.com/linux/chrome/deb stable InRelease       
Ign:6 https://ppa.launchpadcontent.net/bookworm-team/bookworm/ubuntu jammy InRelease
...output truncated...

This way, we ensure that the package management system can install packages from the archive of old Ubuntu releases. Now, we can utilize the apt-get command to install software from old and unsupported Ubuntu releases.

7.2. Upgrading Software

If we installed some software from the archive of old Ubuntu releases and want to upgrade them, we need to modify the software sources in the /etc/apt/sources.list file. We replace the old-releases.ubuntu.com repository with the archive.ubuntu.com repository. Let’s complete this task from the terminal via sed and an in-place update:

$ sudo sed -i -re 's/([a-z]{2}\.)?old-releases.ubuntu.com|security.ubuntu.com/archive.ubuntu.com/g' /etc/apt/sources.list

After performing the replacement, let’s again check the sources.list file:

$ sudo cat /etc/apt/sources.list
# deb http://archive.ubuntu.com/ubuntu/ jammy main restricted

# deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb http://archive.ubuntu.com/ubuntu jammy-security main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
...output truncated...

Furthermore, after modification of the source file, we download the latest software source information and keep the local copy of the package database up-to-date by executing the update command:

$ sudo apt-get update

The update command doesn’t install or upgrade any packages. It only updates the list of software, addresses (URLs), and versions.

Finally, let’s upgrade all the software to their latest versions using the dist-upgrade command. To perform an extensive update, including installing new packages or removing obsolete ones, we pick the dist-upgrade command over the upgrade command:

$ sudo apt-get dist-upgrade

It’s important to note that we might need to restart the computer to complete the updation procedure.

8. Conclusion

In this article, we learned how to upgrade to the latest version of Ubuntu and also touched upon the steps that we can perform before and after the upgrade to keep the distro running smoothly.

Finally, we discussed how to install or upgrade software from the old and unsupported Ubuntu releases.

Comments

Popular posts from this blog

Clearing DNS cache on vCenter Server Appliance

Repairing a virtual disk in Workstation (2019259)