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.
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.
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.
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 -cis the same command. - apt-file search PATH
- Which AVAILABLE package ships a file.
dpkg -Sonly knows about installed ones.
What the exam does with this
apt-getupdate refreshes indexes;apt-getupgrade installs. Swapping them is the most-tested mistake on this objective.dpkg -Llists an installed package's files;dpkg -clists a.debfile's contents.dpkg -Sfinds the owner of a file you have;apt-file searchfinds the package for one you do not.dpkg -rversusdpkg-P: remove keeps configuration files, purge does not.dpkgwill not download anything. If a question mentions fetching dependencies, the answer is an APT command.
- 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
- On a Debian system you have downloaded a single .deb file that is not in any configured repository, and you want to install it. Which command is designed for that job? machine-checked
- Type the command that installs the already-downloaded Debian package file /tmp/htop_3.0.5_amd64.deb using the low-level Debian package tool (not apt). machine-checked
- You know you want a Debian package for reading PDF files but you do not know any package's name. Which command searches package names and descriptions in the local package index for the word 'pdf'? machine-checked
- Select the TWO statements that correctly describe Debian package management on a standard system. machine-checked
- A colleague asks which files the installed Debian package cron put on the system. Which command answers that? machine-checked
- An unexpected binary /usr/sbin/logrotate is present on a Debian server and you want to know which installed package put it there. Which command reports that? machine-checked
- A build fails because /usr/include/zlib.h is missing, and no installed package provides it. Which command finds the Debian package that ships that file so you can install it? machine-checked
- You removed the package nginx with apt-get remove, but /etc/nginx still contains the old edited configuration and a fresh install picks it up again. Which command discards those configuration files as well? machine-checked
- The system clock shows the wrong time zone because the wrong answer was given to the tzdata package's setup questions during installation. Which command presents those questions again without reinstalling the package? machine-checked
- A developer needs to fetch the upstream source of a package with apt-get source, but the command reports that it must find a source package line. Which kind of entry has to be added to /etc/apt/sources.list? machine-checked
- An upgrade is held back because a new version of a package now conflicts with something already installed, so satisfying it requires removing an installed package. Which apt-get subcommand is permitted to do that? machine-checked
- A new repository has just been added to /etc/apt/sources.list.d. Type the apt-get command, including its subcommand and no other arguments, that refreshes the local package indexes from the configured repositories without installing or upgrading anything. machine-checked
- Before installing an unfamiliar package you want to see which files it would place on the system. Type the complete dpkg command, including the option and the file name, that lists the contents of the archive /tmp/htop_3.0.5_amd64.deb without installing it. machine-checked
- Before removing a library package you want to know which other packages in the archive would break because they depend on it. Which command lists them? machine-checked
- Which THREE of these dpkg options query the local database of installed packages, rather than operating on a .deb archive file? machine-checked
Practise Debian package management