LinuxXI · Package ManagementCache and rollback
Package cache, cleanup, and rollback
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
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
$ du -sh /var/cache/apt/archives/ /var/cache/dnf/...Illustrative output
apt cache management
$ sudo apt clean; sudo apt autoclean...Illustrative output
dnf cache management
$ 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:
$ apt-get -s autoremove; dnf autoremove --assumeno...Illustrative output
Protect anything on that list you still need, then remove:
$ sudo apt-mark manual <pkg>; sudo apt autoremove...Illustrative output
Rolling back an upgrade
$ dnf history list openssh-server; sudo dnf history undo <id>...Illustrative output
Old kernels
$ dpkg -l linux-image-* 2>/dev/null | grep ^ii; rpm -q kernel...Illustrative output
Knowledge check
Knowledge check · 4 questions
Q1. What does `apt autoclean` do?
Q2. dnf can roll back a package upgrade without a filesystem snapshot.
Q3. Which of the following are correct cache management practices? Select all that apply.
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.