DEV Community

Cover image for apt update vs apt upgrade: What's the difference?

apt update vs apt upgrade: What's the difference?

Package Managers are fantastic!
Let me tell you what made me say that.

Features of Package Managers:

  • Downloads, installs and updates existing software from a repository.
  • Ensures the integrity and authenticity of the package.
  • Manages and resolves required dependencies.
  • Knows where to put all the files in the Linux file system.

Just imagine performing tasks like checksum verification, installing dependencies, storing components like docs, binaries and config files in different folders manually.

Although for some package managers like "dpkg", you still need to install dependencies manually. But I don't know why would one use package managers like dpkg if we have more advanced package managers which use these low level package managers under the hood and simplifies the task.

"apt" is one such high level package manager.

If you ever googled how to install <package_name> in Ubuntu machine, you'd have probably came across these commands:

sudo apt update
sudo apt upgrade
sudo apt install <package_name>
Enter fullscreen mode Exit fullscreen mode

You might be thinking that we only wanted to install a certain package so why are people suggesting us to execute those 2 additional commands?

Let's understand that.

What does apt update do?

"apt update" updates the package sources list with the latest versions of the packages in the repositories.

Package sources list contains the locations or URLs of some of the repositories from which a package is installed.

You can view this list using the command :

cat /etc/apt/sources.list
Enter fullscreen mode Exit fullscreen mode

It would give output:

Sources List

One such location in these repositories is /ubuntu/dists/bionic-updates/main/source (You can check that here) where Sources.gz file contains all the information about the packages including:

  • Dependencies of the package
  • Latest versions of the package
  • Checksums of the packages to verify integrity
  • And much more as shown in the figure below.

Image description

So, whenever we type in apt update it browses these lists from the repositories and copies the latest version of them to the local system. It actually doesn't install any package on the system.

What does apt upgrade do then?

"apt upgrade" compares the version of all the packages currently installed on the system with the ones in the list we fetched through apt update and upgrades all of them to their latest versions.

Generally, when upgrading all the packages in the system, we merge both apt update and apt upgrade commands in a single line:

sudo apt update && sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

All these things happen in the backend within a few seconds.

Top comments (3)

Collapse
 
darshilparikh2002 profile image
Darshil Parikh

It was a nice information
Thanks โœŒ

Collapse
 
sneh27 profile image
Sneh Chauhan

Glad you liked it!๐Ÿค 

Collapse
 
ratzgabriel profile image
Gabriel

Short and helpful!