How to check if system updates are available in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check for available system updates on a Linux system using the apt package manager. We will cover the essential steps to ensure your system is up-to-date and secure.

You will begin by refreshing the list of available software packages to get the latest information from repositories. Then, you will learn how to list the packages that have available upgrades. Finally, you will simulate the upgrade process to see which packages would be updated without actually performing the installation.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/PackagesandSoftwaresGroup(["Packages and Softwares"]) linux/PackagesandSoftwaresGroup -.-> linux/apt("Package Handling") subgraph Lab Skills linux/apt -.-> lab-558806{{"How to check if system updates are available in Linux"}} end

Refresh package list with apt update

In this step, we'll learn how to update the list of available software packages on your system. This is a crucial first step before installing or upgrading any software, as it ensures you have access to the latest versions and security updates.

We'll use the apt package manager, which is commonly used on Debian-based systems like Ubuntu.

First, open your terminal. You can do this by clicking the Xfce Terminal icon on the left side of your desktop.

Now, type the following command and press Enter:

sudo apt update

Let's break down this command:

  • sudo: As you learned in the previous lab, this stands for "SuperUser DO" and allows you to run commands with administrative privileges. Updating the package list requires these elevated permissions.
  • apt: This is the command-line tool for interacting with the APT package management system.
  • update: This is the specific command we're giving to apt. It tells apt to download the latest information about available packages from the configured software repositories.

When you run this command, you will see output similar to this:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [109 kB]
Get:4 http://security.ubuntu.com/ubuntu jammy-security InRelease [118 kB]
Fetched 346 kB in 1s (301 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
...

This output shows apt connecting to various servers (repositories) to fetch the updated package lists. The exact output might vary slightly depending on the repositories configured on your system and the current state of updates.

After the command finishes, your system now knows about the latest versions of all the software packages it can install.

Click Continue to proceed to the next step.

List upgradable packages with apt list --upgradable

In the previous step, you updated the list of available packages. Now, let's see which of the packages currently installed on your system have newer versions available in the repositories.

We'll use the apt list command with the --upgradable option.

In your terminal, type the following command and press Enter:

apt list --upgradable

Let's look at the command:

  • apt: The package management tool.
  • list: This tells apt that you want to list packages.
  • --upgradable: This option filters the list to show only packages that can be upgraded.

The output will show a list of packages that have newer versions available. The format is typically package-name/distribution version -> new-version.

For example, you might see something like this:

Listing... Done
bind9-dnsutils/jammy-updates 1:9.18.1-1ubuntu1.6 -> 1:9.18.1-1ubuntu1.7
bind9-host/jammy-updates 1:9.18.1-1ubuntu1.6 -> 1:9.18.1-1ubuntu1.7
bind9-libs/jammy-updates 1:9.18.1-1ubuntu1.6 -> 1:9.18.1-1ubuntu1.7
...

This output indicates that packages like bind9-dnsutils, bind9-host, and bind9-libs have newer versions available. The first version number is the currently installed version, and the second version number after the -> is the newer version available for upgrade.

If there are no packages to upgrade, the output will simply show Listing... Done followed by a blank line.

This command is useful for seeing what updates are pending before you decide to install them.

Click Continue to move on to the next step.

Simulate upgrade with apt-get upgrade --dry-run

In the previous step, you saw which packages have updates available. Before actually performing an upgrade, it's a good practice to simulate the process. This allows you to see exactly what will happen without making any changes to your system.

We'll use the apt-get upgrade command with the --dry-run option. Note that apt-get is an older command-line tool for APT, but it's still widely used and works alongside the newer apt command.

In your terminal, type the following command and press Enter:

sudo apt-get upgrade --dry-run

Let's break down this command:

  • sudo: Again, we need administrative privileges to simulate an upgrade.
  • apt-get: The command-line tool for managing packages.
  • upgrade: This tells apt-get that you want to upgrade installed packages to their latest versions.
  • --dry-run: This is the key option here. It tells apt-get to go through the process of determining what would be upgraded, installed, or removed, but without actually performing any of those actions.

The output will show you a summary of the actions that would be taken if you ran the command without --dry-run.

You might see output similar to this:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  bind9-dnsutils bind9-host bind9-libs ...
...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

This output lists the packages that would be upgraded. It also tells you how many packages would be upgraded, newly installed (as dependencies), removed, or kept back (not upgraded due to dependency issues).

Using --dry-run is a safe way to preview the effects of an upgrade before committing to it.

Click Continue to complete this lab.

Summary

In this lab, we learned how to check for available system updates in Linux using the apt package manager. We started by refreshing the list of available software packages from the repositories using sudo apt update. This ensures our system has the latest information about package versions.

Next, we would typically list the packages that have available updates using apt list --upgradable and then simulate the upgrade process without actually installing anything using apt-get upgrade --dry-run. These steps allow us to see which packages would be upgraded and identify any potential issues before performing the actual update.