What does apt-get update command does?

apt-get update command

apt-get update - Retrieve new lists of packages

You many have noticed that most of the examples where you have to install a new package, apt-get update command is used before doing an apt-get install, if you are wondering why we need to make use of this command, lets find out.

apt-get is a package manager for Debian, and Debian-based Linux. When you try to look or install a package it first looks at the list of the packages that are available at the repository from which it downloads the packages. This list is stored locally on your system. If this list is not up to date, you will get an error saying Unable to locate package.

Let's see an example, I have installed a fresh Ubuntu Linux OS in a container, its a minimal OS that does not have all commands installed, not even Sudo, so when I run any command with sudo I get "sudo: not found", if I try to use the apt-get command to install sudo I still get an error,

# apt-get install sudo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package sudo

This is because the local package list does not have information about sudo, if I run apt-get update and then try to install it, it works!

# apt-get update
Get:1 http://ports.ubuntu.com/ubuntu-ports focal InRelease [265 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease [114 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease [108 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease [114 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports focal/restricted arm64 Packages [1317 B]
Get:6 http://ports.ubuntu.com/ubuntu-ports focal/main arm64 Packages [1234 kB]
Get:7 http://ports.ubuntu.com/ubuntu-ports focal/multiverse arm64 Packages [139 kB]
Get:8 http://ports.ubuntu.com/ubuntu-ports focal/universe arm64 Packages [11.1 MB]
Get:9 http://ports.ubuntu.com/ubuntu-ports focal-updates/multiverse arm64 Packages [9090 B]                 
Get:10 http://ports.ubuntu.com/ubuntu-ports focal-updates/universe arm64 Packages [1079 kB]                 
Get:11 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 Packages [1433 kB]                     
Get:12 http://ports.ubuntu.com/ubuntu-ports focal-updates/restricted arm64 Packages [3933 B]                
Get:13 http://ports.ubuntu.com/ubuntu-ports focal-backports/main arm64 Packages [51.1 kB]                   
Get:14 http://ports.ubuntu.com/ubuntu-ports focal-backports/universe arm64 Packages [26.0 kB]               
Get:15 http://ports.ubuntu.com/ubuntu-ports focal-security/restricted arm64 Packages [3694 B]               
Get:16 http://ports.ubuntu.com/ubuntu-ports focal-security/main arm64 Packages [1076 kB]                    
Get:17 http://ports.ubuntu.com/ubuntu-ports focal-security/universe arm64 Packages [796 kB]                 
Get:18 http://ports.ubuntu.com/ubuntu-ports focal-security/multiverse arm64 Packages [3254 B]               
Fetched 17.6 MB in 14s (1219 kB/s)                                                                          
Reading package lists... Done

As you can see when I ran apt-get it fetched around 17.6 MB of information about the packages available for my arm64 based system and updated it locally.

Now lets try to install sudo command,

# apt-get install sudo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:

Preparing to unpack .../sudo_1.8.31-1ubuntu1.2_arm64.deb ...
Unpacking sudo (1.8.31-1ubuntu1.2) ...
Setting up sudo (1.8.31-1ubuntu1.2) ...
Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap