Linux Labs

Packages, services, and logs / Stage 1 of 13

Packages, dependencies and repositories

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 8 · theory · 5 min

How apt knows about versions

Nobody hunts for archives by hand: repositories hand them out, and lists of what they contain are kept on the machine.

A repository is a server with package archives. Ubuntu takes packages from its own repositories, and their addresses are written in the APT settings.

There is no need to download archives just to get a list: the machine keeps indexes — lists of packages and versions for each repository. Their copy lives in /var/lib/apt/lists. apt installs a package by name: it finds it in the indexes, downloads the archive together with its dependencies and hands it to dpkg. apt and dpkg change the system as root: without sudo, apt install prints Could not open lock file /var/lib/dpkg/lock-frontend and asks are you root?.

sudo apt update downloads fresh indexes. It does not change installed programs — sudo apt upgrade upgrades those. The training machine has no network: apt update prints Temporary failure resolving 'archive.ubuntu.com' and keeps the old indexes.

Check yourself 1 question

What does sudo apt update change on a machine with a network?

  • apt upgrade upgrades installed packages. After apt update the Installed line of apt-cache policy shows the same version.

  • apt downloads an archive when it installs a package. apt update fetches only the lists, which live in /var/lib/apt/lists.

apt update refreshes the indexes, and afterwards apt-cache policy may show a new candidate. A separate command, apt upgrade, installs new versions.

Key points

  • A repository hands out archives; the indexes on the machine list its packages and versions.
  • apt update refreshes the indexes, apt upgrade the installed packages.
  • apt installs by name from the indexes, dpkg from an archive on disk.
Ubuntu 24.04
Loading…