“sudo apt update” Command Explained For Beginners!

This article is all about demystifying the “sudo apt update” command by learning what it does and how it does it!

For those of you in a hurry, here is the “Short Version” of the answer!

sudo apt update: In a Nutshell!

A simple one-line answer to the question: what does “sudo apt update” do?
would be

“apt update” updates the package sources list to get the latest list of available packages in the repositories

embeddedinventor.com

That’s a lot of jargon thrown into a single sentence!

Let us understand what it all means shall we!

Similar to AppStore and PlayStore, Linux apps also come from marketplaces where developers can upload their apps and which are then verified to be free from malware and made ready to be downloaded.

In fact, the very idea of a “centralized location for storing verified software” originated in the world of Linux before it made it to iOS and Android!

These official “app stores” where you can find apps a.k.a “software packages” are called “repositories” in Linux.

apt enables you to keep track of what software is already installed on your system, what versions they are and what are the latest versions available in the market.

An oversimplified version of the apt’s database is presented in the picture below.

To understand what the command “sudo apt update” does, let’s take a little detour!

On our browsers, if we want to reload a webpage, we usually go for the small circle near the address bar.

When we click the refresh button, what happens is our browser retrieves the webpage again from the webserver to get the most recent or up-to-date version of the webpage.

Similarly, whenever we wish to update the “available version” column in the apt database we click the update button of apt!

On giving the sudo apt update command, apt talks to the repositories in the cloud to get the latest available versions of each of the apps installed in our systems.

This ofcourse is just a simplified big picture of what how apt update works. If you want a deep-dive into the technical details of what apt update does, then go ahead and read the section “sudo apt update: The Technical Details” below!

Don’t worry if the above answer does not make sense to you as that was targeted at more experienced programmers who just wanted to refresh their memories. The rest of this article is dedicated to those of you in the first steps of your journey to becoming a Linux Expert!

By the time you reach the end of this article, I suggest you come back and read this summary once more, I assure you it will make much more sense then!

sudo apt update: A Thorough Explanation

When I was a complete beginner and I needed to install something on my Ubuntu machine, I went online and typed in “How to install <software name> on Ubuntu” and it usually led me to a page with some commands which looked like this

sudo apt update
sudo apt install <software name>

I was just happy that I was able to type something in the Terminal and see it actually working!

I did not pay much attention to what I actually typed in. I guess to beginners, it just feels like a magic spell to get our favorite software installed!

As time went on, so many of my Google searches led to using very similar patterns of “apt update” and “apt upgrade” commands to install stuff and my curiosity got the better of me, which inspired me to learn what these commands do and what happens in the background when you execute these commands.

I decided to put together everything I learned into an “easy-to-digest” article so that it can be useful for beginners!

Without further ado, let’s begin!

The Fundamentals

Let us start with the following question.

How Do Commands Work?

For those of you who love learning via videos, here is one we made to explain this concept!

If you are looking for some quiet reading time, then skip the video and read on!

Nowadays we are all used to applications with fancy graphical user interfaces, with buttons to click and forms to enter data.

But back in the era when graphics hardware was not capable enough to handle fancy graphical user interfaces, people interacted with the computers with simple text-based commands.

This interface is called the Command Line Interface (CLI)

The structure of these “text-based commands” usually looks like this

<software name> <option to click inside software>

If apt were a modern-day application, its interface will likely look something like this

So when you type in the terminal

sudo apt update

what you are doing is opening an application named apt and clicking the button named update!

So next time you look at any Linux command don’t let all the jargon overwhelm you as it’s just an app with some buttons!

Before looking at what happens when you click on the update and upgrade buttons, let us first learn how apps are managed in a Linux system with apt.

What is apt and how it works?

If you are a complete beginner I highly recommend reading the article in the link below before continuing with this one.

A Beginners Introduction To Linux Package managers: apt, yum, dpkg & rpm

Let us start our discussion by answering the following question.

What is apt?

APT stands for Advanced Packaging Tool, which is a tool used to manage apps a.k.a “software packages” that are installed in our system.

The words “manage” above simply refer to these 5 basic tasks

  • install software
  • remove software
  • upgrade software
  • upgrade system and
  • book-keeping/maintaining the list of software installed in our system

Also, it’s worth mentioning that apt is just the improved version of apt-get. apt essentially makes the user experience a little bit better by keeping things simpler. apt-get still has its uses though. If you wish to explore this topic further we have an excellent article on that topic linked below. (you can go ahead and skip the “Nutshell answer” section and start reading from the “Thorough Explanation” section!)

apt vs apt-get: Explained For Beginners!

Coming back to the topic, to understand the role of apt on our systems consider the following analogy.

If your computer is an office and your apps are employees then you can think of apt as the manager who is responsible for the hiring and firing of the employees (apps)

embeddedinventor.com

Now that we know what apt is, it is time to learn how apt works!

How apt works?

Similar to AppStore and PlayStore, Linux apps also come from marketplaces where developers can upload their apps and which are then verified to be free from malware and made ready to be downloaded.

In fact, the very idea of a “centralized location for storing verified software” originated in the world of Linux before it made it to iOS and Android!

These official “app stores” where you can find apps a.k.a “software packages” are called “repositories” in Linux.

apt enables you to keep track of what software is already installed on your system, what versions they are and what are the latest versions available in the market.

An oversimplified version of the apt’s database is presented in the picture below.

Every time we install or delete apps on our systems apt makes sure this database gets updated and maintained so that it portrays the present situation accurately.

Apart from the bookkeeping, apt also enables us to install, delete and update apps that are installed on our system by communicating with repositories in the cloud.

This is of course just the big picture and if you want to get into the nitty-gritty details we have a separate article on that which you can find in the link below!

A Beginners Introduction To Linux Package managers: apt, yum, dpkg & rpm

Now that we understand what apt is and how it works, we are ready to answer the question: what does sudo apt update do?

sudo apt update: The Big Picture

To understand what the command “sudo apt update” does, let’s take a little detour!

On our browsers, if we want to reload a webpage, we usually go for the small circle near the address bar.

When we click the refresh button, what happens is our browsers retrieve the page again from the server again to get the up-to-date version of the webpage.

Similarly, whenever we wish to update the “available version” column in the apt database we click the update button of apt!

On clicking refresh apt talks to the repositories in the cloud to get the latest available versions of each of the apps installed in our systems.

sudo apt update: The Technical Details

Let us take another look at our “jargon-filled” answer from the beginning of the article

“apt update” updates the package sources list to get the latest list of available packages in the repositories

embeddedinventor.com

Here “package sources list” is just jargon for “the list of software-packages” (a.k.a the apps) available for installation on our computers.

Let us take a closer look at these “packages” and see what they are made of!

What are packages in a Linux System?

Linux OS is basically made up of 3 parts

  • The hardware
  • The Linux Kernel and
  • Software packages that work with the Kernel to give us a complete Operating System

In simple words,

  • hardware, as we know, includes CPU, HDD, SSD, RAM, and all the other components that make up your computer.
  • The kernel is a special software that takes all the available hardware resources and virtualizes and manages them.
  • The software packages are typically applications that we run which can make use of these hardware resources by requesting access to them through the kernel.

Examples of software packages can include application software like text editors, word processors, etc. or they can be the GNU utilities like bash, cron, dd, etc., or they can be device drivers to talk to the hardware.

These packages are managed by a special class of software known as “Package managers” which are explained in the article linked here.

Next, let’s have a brief look at what is included in these “Packages” of software.

Contents of packages

The content of the packages involves the following 4 main components

  • Binaries or the executable programs
  • metadata files containing the version, dependencies, signatures, and other relevant information
  • documentation and manuals
  • configuration files

These packages are stored online on servers. These places are called software repositories.

What are Software Repositories?

This is the next question we must address. Repositories (or repos for short) are basically a place where verified packages are stored for easy retrieval and installation. They can be online like the APT repository or they can be on a local folder or a DVD where you have a special collection of software that you need.

This is one of the strong areas of Linux against other operating systems like Windows and Mac OSX, because, on the 2 latter OSes, we usually need to go to the software vendor’s website to download a software package and manually install them, whereas in Linux you can just type one line of code to get your desired software!

Also because we need to go to some untrusted vendor website to download software, which are not curated by the OS, there can be security issues where malware could come along with the download, whereas in Linux as long as you stick to the official software repositories, you don’t need to worry about security issues as these software are already verified before being made available through the repos!

Windows and Mac OSX are improving this situation through their app stores but Linux is miles ahead of other OSes in this race!

You can have several repositories from which you can download and install these packages. These can be

  • official repos of your particular distro (some have guaranteed support while others are not entirely supported) and
  • 3rd party repos

As I said, I would stick to the official repos and only turn to 3rd party repos if I really trust the repo and I cannot get the software package I need from the official repo.

What is a Package Source List?

This is a list of packages available for installation on a given distro. This list is maintained by your Linux machine. The information in this list usually includes the locations of various repositories from which software can be installed. These locations are usually on the Internet.

This list is often stored in the /etc/apt directory. You can view and edit this list the same way you can view any other text files using one of your favorite text editors like vs-code, gedit, nano, or vim.

If you are using Ubuntu or one of its derivatives, you can also view this list by typing in the following command in the Linux terminal

cat /etc/apt/sources.list

The screenshot below shows the output of the above command.

As you can see from the above screenshot, this list basically contains some URLs to locations on the internet. From these locations, further information can be collected like

  • the latest bug fix updates
  • the latest version of each available package in the main repo
  • the latest version of each available package in the partner repos

If a particular URL has “#” in front of it, it will be ignored as comments.

Let’s go ahead and visit one of these repos to see what it actually contains. You can try going to this link. The screenshot below shows its contents.

Downloading and extracting the Sources.gz file gives a file named “Source” with no file extension. You can open it using any text editor and it reveals a massive file with more than 28,000 lines!

The screenshot above shows one of the packages named zsh (an alternative to bash shells), and the information it contains.

As you can see it contains information like

  • the latest version of the software
  • the dependencies of this particular software etc.

Let us see what the official documentation has to say about apt!

You can get the documentation using the following command.

man apt

and you will get something similar to the screenshot below

To scroll this page, you can use the Enter button to go one line at a time, or you can use the space bar to go one page at a time. If you wish to close this and get back to the terminal, just press the key Q

Now that you know how to move around man pages, let us see if what we just learned is there on the man page for the apt command.

As shown in the screenshot above, if you have a look under the Description sub-heading, you will see the following lines.

apt

apt provides a high-level commandline interface for the package management system. It is intended as an end user interface and enables some options better suited for interactive usage by default compared to more specialized APT tools like apt-get(8) and apt-cache(8).

apt man page

update

update is used to download package information from all configured sources. Other commands operate on this data to e.g. perform package upgrades or search in and display details about all packages available for installation.

apt man page

By “configured sources” the manual means the sources listed in the /etc/sources.list file.

As you can see, we can get the needed information from within the Linux CLI! This is one of the many features of CLI that is very useful especially when you know what command to use but you don’t know what option to use with the command to achieve what you desire!

Summary

The screenshot below shows what the output of our command looks like.

output: sudo apt update

Your output might look a bit different than mine, but the important things to note here are the “Hit“s at the beginning of each line of the output. All of these web addresses are repos that contain software.

As you can see the last line says “Reading package lists… Done” which means that my computer went ahead and read all the available software in the repos and compared them with the version present on our end and found that they are up-to-date!

So in essence, what we are doing when we enter this “sudo apt update” command is we are asking our Linux machine to go browse these lists and copy the latest version of them and put them in our computers!

That is the meaning of the sudo apt update command!

Another interesting fact is that there is another command which does exactly the same thing.

sudo apt-get update

Notice here we use the command apt-get instead of the command apt. Both apt and apt-get have their place in the Linux operating system, you can learn more about their differences in the article given below.

apt vs apt-get Explained For Beginners!

Alright, I will stop here, hope you have enjoyed reading this article and found it useful!

If your thirst for knowledge is not quenched yet, here are some articles that might spark your interest!

Related Articles

“sudo apt-get install” Command Explained For Beginners!

apt vs apt-get: Explained For Beginners!

A Beginners Introduction To Linux Package managers: apt, yum, dpkg & rpm

Linux Distros That Uses apt commands for Package Management

Photo of author
Editor
Balaji Gunasekaran
Balaji Gunasekaran is a Senior Software Engineer with a Master of Science degree in Mechatronics and a bachelor’s degree in Electrical and Electronics Engineering. He loves to write about tech and has written more than 300 articles. He has also published the book “Cracking the Embedded Software Engineering Interview”. You can follow him on LinkedIn