TT Lab
Blog Get started
Learn Learning paths Courses

Package Management

Handling Packages With apt

Continue in TT Lab

Goal

You search, install, and remove with apt, and get used to holding a version in place with hold and pin. When this lab is finished, you can explain "why this version was picked" from the apt-cache policy output alone, and you can split reports that "we updated, but the old version is installed" by cause.

Why it matters

apt does not ask the repository in real time. It judges only from the index cached in /var/lib/apt/lists/, and when the same package is in several repositories, it picks by priority. Once you know this structure, both "it's in the repository but I can't see it" (the index is stale) and "I added the internal mirror but it fetches from the official one" (the priorities are the same) are explained at once. This lab environment has no internet and only the /opt/localrepo offline repository, so every installation happens from that repository.

The last step is an incident. "We updated, but the old version is installed" is the most common report in the field, and behind the same symptom hide completely different causes: hold, pins, dependencies, and a stale index. If you push through with --force or "just remove it and reinstall" without telling the causes apart, the same thing repeats at the next update or a bigger outage happens. The policy queries, hold, and pins you got used to in the earlier steps become your diagnostic tools as they are.

Steps

  1. Create the /root/pkg directory and save the full output of apt-cache policy to /root/pkg/policy.txt.
  2. Search for a package named tree and save the result to /root/pkg/search-tree.txt. The result must contain a line whose name is exactly tree.
  3. Write only the install candidate version of tree on one line in /root/pkg/tree-version.txt. (For example: 2.1.1-2ubuntu3)
  4. Install the two packages tree and ncdu.
  5. Install cowsay, pick out only the Depends line of its dependencies, and save it to /root/pkg/cowsay-depends.txt.
  6. Install htop, exclude it from upgrades (hold), and save that fact to /root/pkg/hold.txt.
  7. Create /etc/apt/preferences.d/labhub.pref and pin the htop package at priority 1001. All three lines Package, Pin, and Pin-Priority must be present.
  8. Incident: run incident pk-stuck-old and read the ticket. Four acme packages fail to receive the 2.0 update and stay on 1.0-1. Upgrade those that can be upgraded to 2.0-1 so they keep following in the next update too, and leave alone those whose dependencies would break. In /root/incident/pk-stuck-old/report.txt, write a cause code for each package (dep-unmet, hold, not-in-repo, pin, stale-index) and one evidence: line.

Notes

Working directory and repository check

Create the /root/pkg directory and save the full output of apt-cache policy to /root/pkg/policy.txt.

If you run apt-cache policy without arguments, it prints all the repositories and priorities currently configured. Save that output to a file.

Searching for a package

Search for a package named tree and save the result to /root/pkg/search-tree.txt. The result must contain a line whose name is exactly tree.

apt-cache search searches names and descriptions. The result must contain a line whose name is exactly tree.

Checking the install candidate version

Write only the install candidate version of tree on one line in /root/pkg/tree-version.txt. (For example: 2.1.1-2ubuntu3)

It is the value on the Candidate line of apt-cache policy . Write only the version string on one line.

Installing packages

Install the two packages tree and ncdu.

After installing, check the state with dpkg -s. Only if the Status line is 'install ok installed' is it really installed.

Pulling out the dependency list

Install cowsay, pick out only the Depends line of its dependencies, and save it to /root/pkg/cowsay-depends.txt.

The dependency list comes from the index whether or not the package is installed. The apt-cache subcommand that shows dependency relations also prints layers such as Recommends, Suggests, and Breaks besides Depends, so keep only the Depends lines with the tool's own filtering options or a line filter. Do the install separately afterward.

Excluding from upgrades

Install htop, exclude it from upgrades (hold), and save that fact to /root/pkg/hold.txt.

apt-mark has the subcommands hold / unhold / showhold. Also check that the mark was actually set.

Setting priority with a pin file

Create /etc/apt/preferences.d/labhub.pref and pin the htop package at priority 1001. All three lines Package, Pin, and Pin-Priority must be present.

In a pin file, the three lines Package / Pin / Pin-Priority form one group. Pin starts with one of version, release, or origin.

Incident: supposedly updated, but four packages stay on the old version

Running incident pk-stuck-old raises an incident in four acme packages that use the internal mirror (read the ticket first). Symptom: the 2.0 security update has supposedly been published to the mirror, but all four of acme-agent, acme-cli, acme-report, and acme-sync stay on 1.0-1. Upgrade those that can be upgraded to 2.0-1, and make them keep following in the next regular update as well. Leave those whose dependencies would break if upgraded now at 1.0-1: forcing them in, removing them, or crafting and adding what is not on the mirror is a failure. Do not touch the holds and pins of non-acme packages. In /root/incident/pk-stuck-old/report.txt, write four lines <패키지>: <코드> (package: code) and evidence: <관찰한 출력 한 줄> (one line of output you observed). The code is one of dep-unmet (something the new version requires is missing), hold (an administrator held it), not-in-repo (the new version is not on the mirror), pin (another version wins by priority), or stale-index (this server's index is stale).

Direction: even if "the old version is installed" is the same, apt picking 2.0 as the candidate but failing to upgrade and picking 1.0 as the candidate in the first place are different stories. First split the four into those two groups. Tools: apt-cache policy (installed version, candidate, priorities in the version table), apt-mark, apt-get's simulated run (-s), and the index files in the mirror directory. Concretely: for those whose candidate is 2.0 but were not upgraded, look at the administrator's marked list and the dependencies the simulated run reports. For those whose candidate is 1.0, compare the numbers on the left of the version table (priorities), /etc/apt/preferences.d, and the versions written in the index this server downloaded and in the mirror's Packages file.