Skip to main content
RunBook Academy

LinuxXI · Package ManagementCache and rollback

Package cache, cleanup, and rollback

Foundation⏱ ~8 minbashaptdnfdpkgrpm

What you'll learn

  • Manage the package cache to control disk usage
  • Clean up unused dependencies and old kernels under review, never unattended
  • Roll back a package upgrade when it breaks
  • Configure cache retention for production fleets

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

The package cache — every .deb or .rpm ever downloaded — is one of the largest consumers of disk on a host. The discipline is to keep what you need for rollback, evict what you do not.

The cache directories

Read-only / Safecache size
$ du -sh /var/cache/apt/archives/ /var/cache/dnf/
...

Illustrative output

apt cache management

Configuration changeapt clean / autoclean
$ sudo apt clean; sudo apt autoclean
...

Illustrative output

dnf cache management

Configuration changednf clean
$ sudo dnf clean all; ls /etc/dnf/dnf.conf | xargs grep -E 'keepcache|metadata'
...

Illustrative output

Removing unused dependencies

Always simulate first and read the list:

Read-only / Safeautoremove (dry run)
$ apt-get -s autoremove; dnf autoremove --assumeno
...

Illustrative output

Protect anything on that list you still need, then remove:

Data-loss riskautoremove (after review)
$ sudo apt-mark manual <pkg>; sudo apt autoremove
...

Illustrative output

Rolling back an upgrade

Data-loss riskrollback
$ dnf history list openssh-server; sudo dnf history undo <id>
...

Illustrative output

Old kernels

Read-only / Safeinstalled kernels
$ dpkg -l linux-image-* 2>/dev/null | grep ^ii; rpm -q kernel
...

Illustrative output

Knowledge check

Knowledge check · 4 questions

  1. Q1. What does `apt autoclean` do?

  2. Q2. dnf can roll back a package upgrade without a filesystem snapshot.

  3. Q3. Which of the following are correct cache management practices? Select all that apply.

  4. Q4. A nightly playbook runs `apt autoremove -y` across the fleet. One morning an internal service fails to start on every host with a missing shared library. What is the most likely cause?

Passing score: 75%. Answers are checked in this browser.