Skip to content
Linux Administration
Lab 14 of 27·25mBeginner

Day 09: Packages and updates

Install, inspect and pin packages, and find out which package owns a file you did not expect to be there.

You need

  • A Debian or Ubuntu system with sudo access

Do first

Written for apt. On RHEL-family systems the same five questions have dnf answers, noted at the end.

1. Refresh, then look before you leap

sudo apt-get update
apt list --upgradable

update refreshes the package lists and installs nothing — the most misunderstood command in the family. upgrade is what changes your system. Always run the first and read --upgradable before the second.

Verify

apt list --upgradable 2>/dev/null | head -n 1 # Listing... (possibly with nothing after it, which is fine)

2. Install and inspect

sudo apt-get install -y tree
apt show tree | head -n 12
dpkg -L tree | head -n 10

apt show is the metadata: version, dependencies, description. dpkg -L lists every file the package placed on disk — the answer to "where did this actually install to".

Verify

dpkg -L tree | grep -c '/usr/bin/tree' # 1

3. Work backwards from a file

dpkg -S /usr/bin/tree
dpkg -S /etc/ssh/sshd_config

This is the one that earns its keep during an incident. You find an unfamiliar binary and need to know whether a package put it there or a person did. No output at all means no package owns it — which is worth a second look.

Verify

dpkg -S /usr/bin/tree # tree: /usr/bin/tree

4. Pin a version you must not change

sudo apt-mark hold tree
apt-mark showhold
sudo apt-get install -y tree

The install becomes a no-op and says the package is held. This is how you stop an unattended upgrade from moving a version your application is pinned against. The matching mistake is holding something and forgetting — apt-mark showhold belongs in whatever you use to audit a machine.

sudo apt-mark unhold tree
apt-mark showhold

Verify

apt-mark showhold | grep -c tree || echo "0" # 0

5. Remove, and understand the two kinds of removal

sudo apt-get remove -y tree
dpkg -l tree | tail -n 2
sudo apt-get purge -y tree
dpkg -l tree | tail -n 2
sudo apt-get autoremove -y

remove deletes the program but leaves configuration, so dpkg -l shows state rc — removed, config remaining. purge takes the config too. When a reinstall keeps inheriting settings you thought you deleted, remove is why.

autoremove drops dependencies nothing needs any more. Read what it proposes; it occasionally offers to remove a kernel you are running.

Verify

dpkg -l tree 2>/dev/null | grep -c '^rc' || echo "0" # 0 after the purge

The RHEL-family equivalents

TaskDebian/UbuntuRHEL/Fedora
Refresh listsapt-get update(automatic)
Installapt-get install Xdnf install X
Which package?dpkg -S /pathrpm -qf /path
Files in packagedpkg -L Xrpm -ql X
Pin a versionapt-mark hold Xdnf versionlock X

Where this goes next

Nine days of guided labs. Tomorrow has no steps: a service that will not start, and everything you need to diagnose it is in Days 06 to 09.