What Do ‘sudo apt update’ and ‘sudo apt upgrade’ Do?

What Do ‘sudo apt update’ and ‘sudo apt upgrade’ Do (1)

Linux has an advanced package management tool called Advanced Package Tool, commonly referred to as APT (apt).

It consists of a bunch of tools that can install, update, remove, or manage the packages that are installed or available for distribution. APT works by the use of repositories. Repositories, also called repos, are storage locations for maintaining software packages.

Software packages can be software like text editors, IDEs, media players, device drivers, and more. Most software packages contain an executable program, metadata files, documentation, and configuration files.

sudo apt update and sudo apt upgrade are two of the most used commands in Ubuntu and Debian-based distributions. You might remember the first time you tried to install a package in your system and used these commands as follows.

sudo apt update
sudo apt upgrade
sudo apt install <PackageName>

Or maybe you needed to fix something, and an article suggested you run these commands. Whatever your goal, the use of apt update and apt upgrade is inevitable.

Many users are curious about the differences between these two commands, and many Linux forums are flooded with this question. Superficially, update and upgrade sound similar, and as the other words are already the same, both should do the same thing. But they are fundamentally very different based on their job description.

It is, however, true that both needed to be worked on simultaneously in most cases.

Difference Between the sudo apt update and sudo apt update Commands

Let’s learn the sudo apt update command in detail first.

As you’re trying to add or modify packages, you need to have root privileges. sudo lets you do that. apt, as mentioned earlier, invokes the Advanced Package Tool. sudo apt update updates the list of all packages that are available along with their versions.

It is necessary to note that update doesn’t install any packages or even upgrade them. The command checks for the latest list of available packages in the repositories. When we enter this command, we send a command to browse the package list and copy the latest version to our local machine.

On the contrary, sudo apt upgrade updates all the currently installed packages in our machines to their latest versions.

When we enter this command, we’re sending a command to our machine to check and compare the versions of all the packages that are installed in our machine currently with the packages in the list that we copied earlier through sudo apt update, and then upgrade the packages whose newer versions are available.

So, we use these commands in the following order:

sudo apt update
sudo apt upgrade

These commands can also be written in the following form.

sudo apt update && sudo apt upgrade

Note that it isn’t mandatory to use these two commands together all the time. In case you do not want to install all the newer versions that are available for several packages and only want one in specific, you can do that by running:

sudo apt update
sudo apt install <package_name>

Here we skipped installing all new packages entirely and only installed one new package(or version).

How to Use the apt update and apt upgrade Commands?

Now, let’s implement these commands practically.

First, use the sudo apt update command. Then, it asks for your system password. Enter your password and press Enter. The output looks something like this.

Hit:1 http://packages.microsoft.com/repos/code stable InRelease
Hit:2 http://dl.google.com/linux/chrome/deb stable InRelease                                       
Hit:3 https://repo.skype.com/deb stable InRelease                                                  
Hit:4 https://packages.sury.org/php bullseye InRelease              
Hit:5 http://kali.cs.nctu.edu.tw/kali kali-rolling InRelease
Reading package lists... Done                        
Building dependency tree... Done
Reading state information... Done
1908 packages can be upgraded. Run 'apt list --upgradable' to see them.

You can use the following command to see the packages that can be upgraded.

apt list --upgradable
Output
3270-common/kali-rolling 4.1ga10-1.1+b1 amd64 [upgradable from: 4.1ga10-1.1]
aapt/kali-rolling 1:10.0.0+r36-9 amd64 [upgradable from: 1:10.0.0+r36-3]
accountsservice/kali-rolling 22.08.8-1 amd64 [upgradable from: 22.07.5-1]
adduser/kali-rolling,kali-rolling 3.123 all [upgradable from: 3.121]

The output above displays just a small portion of upgradable packages.

Next, use the sudo apt upgrade command. You should see something like this:

Notes/ByteXD Articles/What Do 'sudo apt update' and 'sudo apt upgrade' Do/installed_package.png

The output shows the automatically installed packages due to some dependency resolution. These packages are of no use to you.

You can remove these packages with the sudo apt autoremove command.

Let’s see the other part of the output of the sudo apt upgrade command.

Notes/ByteXD Articles/What Do 'sudo apt update' and 'sudo apt upgrade' Do/to_be_installed_packages.png

These are the new packages that will be installed in your system.

The output below shows the list of the packages to be upgraded.

Notes/ByteXD Articles/What Do 'sudo apt update' and 'sudo apt upgrade' Do/to_be_upgraded.png

In the end, you will see a prompt showing the amount of storage required for the upgrade; and asking for your permission.

Notes/ByteXD Articles/What Do 'sudo apt update' and 'sudo apt upgrade' Do/prompt.png

You should enter Y, y, or yes to continue the upgrade. You should enter n, N, or no to resist.

If you continue with the upgrade, it will download and unpack the packages. Finally, the packages will be installed and upgraded.

One thing to note about the sudo apt upgrade command is that it only upgrades packages and dependencies but doesn’t remove anything. That is, the old packages will exist unless removed with another code.

Another thing to note would be the difference between apt and apt-get. In this article, we used apt. But, you may see the use of apt-get elsewhere.

These commands can be used interchangeably for the most part. Both of them update the package list on your system. The only difference would be that the output from apt is more useful. It has a user-friendly progress bar.

Conclusion

In this article, we learned about the uses of the sudo apt update and sudo apt upgrade commands and the difference between them. We also practically implemented these commands and studied the result.

0 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)

0 Comments
Inline Feedbacks
View all comments
You May Also Like