What does sudo apt-get update command do on Ubuntu/Debian?

I am a new Ubuntu / Debian Linux user. I wanted to know what does sudo apt-get update command does? What does it update and how do I tell apt-get to update? What does “sudo apt-get update” do on my Debian Linux server? What is the difference between “sudo apt-get update” and “sudo apt-get upgrade“?

Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements Ubuntu or Debian Linux and friend
Time 5m
Introduction: Debian and Ubuntu Linux are both free and open source operating system. Both systems use the Linux kernel and GNU commands. One can use apt command or apt-get command to manage software operations such as adding, removing, deleting, updating and so on. However new users often get confused with “sudo apt-get update” and “sudo apt-get upgrade” commands on a Debian or Ubuntu Linux system. After all, what does “sudo apt-get update” command do? This page explains the fundamental differences between the two commands.

What does sudo apt-get update command do?

  1. The sudo apt-get update command is used to download package information from all configured sources.
  2. The sources often defined in /etc/apt/sources.list file and other files located in /etc/apt/sources.list.d/ directory.
  3. So when you run update command, it downloads the package information from the Internet. It is useful to get info on an updated version of packages or their dependencies.

How to see /etc/apt/sources.list file

Type the cat command:
$ cat /etc/apt/sources.list

Run sudo apt-get update command to update package index

Simply type apt-get command or apt command:
$ sudo apt update
OR
$ sudo apt-get update

What does sudo apt-get upgrade command do?

  1. Now you know sudo apt-get update command gets you an updated list of packages from the Internet.
  2. But, how do you install outdated packages? How do you apply security patches for packages and keep your system secure? How do you find new packages to install?
  3. You run sudo apt-get upgrade to install available upgrades of all packages currently installed on the system from the sources configured via sources.list file.
  4. New packages will be installed if required to satisfy dependencies, but existing packages will never be removed.

The differences between update and upgrade command

From the apt-get update man page:

update is used to resynchronize the package index files from their sources. The indexes of available packages are fetched from the location(s) specified in /etc/apt/sources.list. For example, when using a Debian archive, this command retrieves and scans the Packages.gz files, so that information about new and updated packages is available. An update should always be performed before an upgrade or dist-upgrade. Please be aware that the overall progress meter will be incorrect as the size of the package files cannot be known in advance.

From the apt-get upgrade man page:

upgrade is used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list. Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. An update must be performed first so that apt-get knows that new versions of packages are available.

Conclusion

In short executing “sudo apt-get update” fetches you a list of packages for all of your repositories and PPA’s and make sure it is up to date. While “sudo apt-get upgrade” does an actual software upgrade. Hence, it recommended option is always to run update command before upgrade command to update installed packages for an Ubuntu or Debian system:
$ sudo apt-get update && sudo apt-get upgrade
One can run multiple commands in sudo as follows:
$ sudo sh -c 'apt update && apt upgrade'

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • TickTakTo Nov 21, 2009 @ 13:00

    The update command updates the available software list on your system. This is how you get updated drivers or software.
    apt-get update # get me a list of updated software, will ya?
    apt-get upgrade # kind sir, please install updated kernel and driver. thank you~!

  • A debian fan girl May 3, 2010 @ 16:55

    Whatever you do always run apt-get update before installing anything new. Same goes for patching my Debian server.

    apt-get update
    apt-get install foo
    apt-get update && apt-get upgrade
  • zPlus Nov 8, 2020 @ 21:23

    Awesome page, dude. thanks a lot

  • dummy ub user Dec 1, 2020 @ 10:03

    Excusme, where is all my apt update file and how to save / backup all file / pkg in proses, apt-get update ? Do I need to backup all folder/file in /etc/apt/
    so when I reinstal ubuntu I no need to download it anymore.
    please.. please help >.^
    How to backup all this file

    http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages
    http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en
    http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata
    http://archive.ubuntu.com/ubuntu focal/main i386 Packages
    http://archive.ubuntu.com/ubuntu focal/multiverse i386 Packages
    http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
    http://archive.ubuntu.com/ubuntu focal-updates/main i386 Packages
    http://archive.ubuntu.com/ubuntu focal-updates/main Translation-en
    http://archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata
    http://archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata
    Get:30 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [11.0 kB]                                                             
    Get:31 http://archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [3000 B]                                                              
    Get:32 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [116 B
    

    thanks

    • 🐧 Vivek Gite Dec 2, 2020 @ 10:24

      We don’t backup those files. What we backup is user data, database files and other stuff stored in /etc/, $HOME, /var/ and so on. But, if you need them, look into the following directories and files:

      1. /etc/apt/sources.list: Locations to fetch packages from.
      2. /etc/apt/sources.list.d/ : File fragments for locations to fetch packages from.
      3. /var/lib/apt/lists/ : Storage area for state information for each package resource specified in sources.list
      4. /var/lib/apt/lists/partial/ : Storage area for state information in transit.

      I hope this helps. If not feel free to open thread at https://www.nixcraft.com forum.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.