Fast And Easy Explanation of sudo apt update Command

sudo code

sudo code

The sudo apt update command is one of the first commands a Linux newbie learns to use. The command instructs a Linux machine to download and update all the package information from every source configured on the machine. 

But what are packages? What are the sources we are referring to? And where are we supposed to run this command?

We explain how the sudo apt update command works in this brief guide. 

The Linux Command-line

The Terminal is the information transfer mechanism that allows you to communicate with your Linux machine. 

A command line is a line of text instructing the machine to perform an action. These lines are entered in the Terminal. Command lines must be used according to their syntax – plain English won’t work with Linux or any operating system. 

So, you cannot run “please install software” on Linux and expect the same result as “sudo apt install.” 

Though technology has advanced and artificial intelligence is getting smarter at an unprecedented rate, our methods of communicating with machines remain somewhat primitive for the sake of efficiency.  

The world will probably never see the day when the command line is replaced by voice input.

A command line is comprised of four parts:

  1. Command
  2. Sub-command
  3. Options and 
  4. Arguments

For a command line to be valid, it must always have a command in it. Users may use sub-commands, options, and arguments per their needs and discretion. 

Now that you understand what the Terminal is and how command lines work let’s understand the meaning of the words in the sudo apt update command line.

Explanation of sudo apt update Command

“apt” is the command, and “update” is the sub-command in this command line. There are no arguments or options in it. 

“sudo” is short for “super user do,” and this term allows the user to get administrative privileges. Getting super user access is essential when installing or removing software on any Linux distro.

“apt” is short for “Advanced Packaging Tool,” and as you might be able to guess, it is a tool that facilitates software management in Linux. Besides allowing you to install and remove software, the command facilitates software and system upgrades. It is also used to maintain the list of installed software. 

If your computer were a factory, the apt command would be its manager, taking care of installing, removing, and upgrading the factory’s equipment. Of course, this manager would also record the equipment’s names and current versions. 

You must enter the super user’s password when you run the sudo command. This is a standard security measure in all Linux distros to prevent malware installations and attacks. 

Back to our factory analogy, you can think of using sudo as giving your factory’s manager permission to use the company credit card to install or remove equipment.

Finally, the sub-command “update” instructs the advanced packaging tool to update all packages.  

What are Packages in Linux?

The Linux operating system comprises the hardware, the kernel, and software packages. These packages work with the kernel to provide the user with a complete operating system.

The kernel is a specially-designed software that communicates with, virtualizes, and manages all the hardware resources. In contrast, software packages are applications that use hardware resources via the kernel.

A software package can be an application such as a word processor or video player and a GNU utility such as cron or bash. The device drivers on your Linux machine are also software packages. 

There also exists a special class of software called package managers that manage all the packages on a Linux machine. 

All software packages have four components:

  • Binaries/executable programs
  • Configuration files
  • Manual/documentation
  • Metadata files containing the version, dependencies, signatures, and other relevant information

Verified software packages are stored on servers called software repositories (or “repos”) and made available by the provider. So, the provider’s software repo is the “source” of the packages we referred to early in this post. 

Some developers find using Linux more convenient because they don’t have to navigate a clunky app store or find software packages online to install software. They can simply type a command line and install any software they want. 

Plus, on Linux, there is no question of getting a software package from an untrusted source. Windows and macOS users often install software not curated by the operating system. This is often the cause of security issues, such as malware attached to a software package that users download. 

As long as you use the official software repos on Linux, you never have to worry about security issues. The security of the software is verified before it is distributed via a repo.

Though the app stores on Windows and macOS have gotten more secure over the years, Linux has always been miles ahead. You can install software packages from your distro’s official repo or third-party repos. Many official repos guarantee support, but some don’t. 

Significance of Package Source List

The package source list is a list of the packages available on a distro. Your distro maintains this list. Besides the package information, it stores the locations of the repos where the package can be installed. The locations are typically servers.

The package source list is stored in the /etc/apt directory on most distros. You can use any text editor to view and edit this list. You can also use the cat command to view the list like so: 

cat /etc/apt/sources.list

 

When you run this command, you will see a list with several URLs. You will also see some notes that indicate bug fix updates, whether certain repos are supported by your distro, and instructions to access certain packages. 

You can visit the URLs in the list to find specific information about that package, such as its latest bug fixes, the latest version available in the main repo, and the latest version available in partner repos. 

You can also find the source code of a package on its repo URL. All you have to do is look for a Source.gz file and extract it. Opening the file inside the archive that doesn’t have a file extension with a text editor will allow you to see the entire source code.

You may also see a package named “zsh.” The zsh file is an alternative to bash shells, and these packages hold information about the dependencies and the latest version of the package. 

Note that if you see a URL with a pound sign in front of it, it is ignored since it is a comment. 

Summing Up: What Does the sudo apt update command Do?

Now that you know about all the building blocks of the sudo apt update command, you can run the command in your Terminal and see the output.

The output of this command is slightly different on every distro. However, you will see several URLs in the output, which are the software repos associated with the software packages on your machine. 

You may also see a line stating, “Reading package lists… Done!”

This line indicates that your machine visited all the software repos, fetched the latest software package information, and compared it with the software packages on the machine. It found that all the packages on the machine are up to date.

Thinking back to our factory analogy, you can think of the sudo apt update command as us instructing the factory manager to use its list of available parts from various equipment managers to contact them and inquire about the latest equipment. 

Additionally, with this command, we are also instructing the manager to update their list of equipment with the latest information. 

One of the best ways to learn more about this command is to access its man page. The man page, or manual page, holds all the information about how a command works, including the functions of the available arguments and options. 

To access the apt command’s man page, you can run:

man apt

 

You will see a description of the command and all the available options and arguments. You can scroll this page one line at a time by hitting the Enter key. You can also hit the space bar to scroll one page at a time. You can close the man page and return to the Terminal by hitting “Q.” 

Also, note that you can also run the following command instead of sudo apt update:

sudo apt-get update

 

This command serves the same function and is the older version of the sudo apt update command. It doesn’t have a progress bar like sudo apt update does; however, it offers more features and is often used with bash scripts since it guarantees backward compatibility. 

It’s noteworthy that the apt-get family of commands is larger than the apt family of commands. Several apt-get commands have no substitutes in the apt command family. 

But you don’t have to worry about apt-get commands unless you want to work with bash scripts. With this brief guide handy, you know everything there is to know about the sudo apt update command!