Debian package management

Debian package management: dpkg for one .deb file at a time, APT for repositories and dependency resolution, and the division of labour between them.

Lesson 4 of 6 in objective 102. Linux installation and package management, part of LPIC-1 Exam 101-500.

Two levels: one knows the file, the other knows where files come from. dpkg — Operates on: One .deb file you already have; Downloads: Never; Missing dependency: Refuses to install; Asks the questions: dpkg-reconfigure. apt / apt-get — Operates on: Repositories in sources.list; Downloads: Yes, after apt-get update; Missing dependency: Fetches it first; Asks the questions: Delegates to dpkg dpkg apt / apt-get Operates on One .deb file you already have Repositories in sources.list Downloads Never Yes, after apt-get update Missing dependency Refuses to install Fetches it first Asks the questions dpkg-reconfigure Delegates to dpkg
Two levels: one knows the file, the other knows where files come from.

dpkg is the low level

dpkg installs, removes and queries individual package files. It knows about dependencies in the sense that it refuses to install a package whose dependencies are missing — but it will not go and fetch them, because it has no idea where packages come from. dpkg -i installs a file, dpkg -r removes a package but keeps its configuration, and dpkg -P purges it including configuration. dpkg -l lists installed packages, dpkg -L lists what a package installed, and dpkg -S finds which package owns a given file.

dpkg-reconfigure re-runs a package's configuration questions after installation, which is the answer whenever a question asks how to change something you were asked during install. dpkg --get-selections and --set-selections copy the set of installed packages from one machine to another.

A second group of operations works on a .deb FILE rather than on the installed database, and the exam keeps them apart from the query flags for exactly that reason. A .deb is an archive with a control member and a data member, and dpkg -c (long form --contents) lists the data member — every file the package WOULD place on the system — without installing any of it, while dpkg -e and dpkg -x extract the control files or the data. All of them are really dpkg-deb, which dpkg hands the request straight to, so dpkg-deb -c htop.deb and dpkg -c htop.deb are one command under two names, and dpkg-deb -I prints the control information. The pair that reads alike and is not alike: dpkg -L lists the files of an INSTALLED package, dpkg -c lists the contents of a file sitting on disk.

What dpkg -r leaves behind, and what dpkg -P takes away with it. A column of 3 states: Not installed (No files, and no configuration either); Installed (dpkg -l lists it); Removed, configuration kept (The program is gone; its configuration is not). You get from Not installed to Installed by dpkg -i, on the .deb file itself; from Installed to Removed, configuration kept by dpkg -r; from Removed, configuration kept to Not installed by dpkg -P, which finally takes the configuration too; from Installed to Not installed by dpkg -P, straight from installed, in one step. Not installed No files, and no configuration either dpkg -i, on the .deb file itself Installed dpkg -l lists it dpkg -r Removed, configuration kept The program is gone; its configuration is not dpkg -P, straight from installed, in one step dpkg -P, which finally takes the configuration too
What dpkg -r leaves behind, and what dpkg -P takes away with it.

APT is the level that knows where packages live

APT reads /etc/apt/sources.list and the files in /etc/apt/sources.list.d/, downloads package indexes with apt-get update, and resolves dependencies before installing. apt-get install fetches and installs with everything it needs; apt-get upgrade upgrades installed packages without removing any; apt-get dist-upgrade (or apt full-upgrade) is allowed to add and remove packages to satisfy a larger change. apt-cache search and apt-cache show query the indexes, and apt-cache depends walks a dependency tree.

The apt command is the newer, friendlier front end over the same machinery — apt install, apt search, apt list --installed — intended for interactive use. aptitude is a third front end with its own dependency resolver and a full-screen interface. All three ultimately act on the same dpkg database.

There are two file-to-package searches on this family and they differ in scope, which is the whole question. dpkg -S reads the file lists under /var/lib/dpkg/info, so it can only answer about packages already installed and says nothing at all about a header like /usr/include/zlib.h that is missing precisely because its package is not there. apt-file search /usr/include/zlib.h searches the Contents indexes the repositories publish, so it names the package to install; it is a separate package on most systems, and its index has to be fetched with apt-file update before the first search. dnf provides is the same question on the RPM side.

Which commands only read the indexes, and which write to the dpkg database. Left column, The command you type; right column, What it actually touches. apt-get update, apt-cache search and apt-cache show all point at The package indexes (update downloads them from sources.list and sources.list.d; apt-cache only reads them). apt install, apt-get install, apt-get upgrade and aptitude install all point at The dpkg database (Dependencies are resolved from those indexes first; three front ends, one database). The command you type What it actually touches apt-get update apt-cache search apt-cache show The package indexes update downloads them from sources.list and sources.list.d; apt-cache only reads them apt install apt-get install apt-get upgrade aptitude install The dpkg database Dependencies are resolved from those indexes first; three front ends, one database
Which commands only read the indexes, and which write to the dpkg database.

Worth carrying in

dpkg -i file.deb
Install one package file. Fails rather than fetching missing dependencies.
dpkg -L pkg
List the files a package installed. -S finds the package owning a file.
dpkg -P pkg
Purge: remove the package and its configuration. -r keeps configuration.
dpkg-reconfigure
Ask the package's setup questions again.
apt-get update
Refresh package indexes. Not an upgrade of anything.
apt-get dist-upgrade
Upgrade, allowing packages to be added and removed.
apt-cache search
Search package descriptions in the indexes.
/etc/apt/sources.list
Where the repositories are declared.
dpkg -c file.deb
List what is inside an archive without installing it. dpkg-deb -c is the same command.
apt-file search PATH
Which AVAILABLE package ships a file. dpkg -S only knows about installed ones.

What the exam does with this

Objective
102. Linux installation and package management
Share of the exam
18.33% (the whole objective)
Questions in this lesson
15
Signed for by a person
0

Partly checked. None of the 15 questions here has been read against the cited source by a person. 15 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.

Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

Drill this lesson

A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.

Practise Debian package management

Questions in this lesson

Practise Debian package management

The rest of objective 102