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?
- The sudo apt-get update command is used to download package information from all configured sources.
- The sources often defined in /etc/apt/sources.list file and other files located in /etc/apt/sources.list.d/ directory.
- 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
What does sudo apt-get upgrade command do?
- Now you know sudo apt-get update command gets you an updated list of packages from the Internet.
- 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?
- 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.
- 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.
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'
|Category||List of Unix and Linux commands|
|Network Utilities||dig • host • ip • nmap|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|