Sub topic 4
Refreshing metadata before you look at updates
Assume you can use a Linux shell, sudo, package repositories, and systemd status commands. This chapter uses Debian/Ubuntu and RHEL-family examples. The commands download information about available packages. They do not install updates.
Why metadata comes first
A package repository stores package files and metadata. Metadata is an index containing package names, versions, dependencies, and repository information. The package manager uses this index to decide whether an update is available.
The local metadata can become stale. If you inspect updates without refreshing it, you might miss a newer security fix or see an update that is no longer available. Refreshing metadata is therefore a separate step from applying updates.
Refreshing apt metadata
On Debian and Ubuntu, apt reads repository definitions from /etc/apt/sources.list and files under /etc/apt/sources.list.d/. Run this before reviewing or installing updates:
sudo apt updateapt update downloads current package lists and checks the repository metadata. It does not upgrade installed packages. Read the output for errors such as an unreachable repository, an expired signing key, or a missing release file. Do not continue with patching until you understand a failed repository check.
The command normally ends with a summary such as “All packages are up to date” only when used with a later update operation. For a useful preview after refreshing, run:
apt list --upgradableRefreshing dnf metadata
On RHEL, Fedora, Rocky Linux, AlmaLinux, and related systems, dnf reads repository definitions from files under /etc/yum.repos.d/. Force a fresh metadata download with:
sudo dnf makecache --refreshThe --refresh option ignores metadata that is still within its normal validity period. This is useful before a planned maintenance window or after a repository administrator publishes an urgent fix.
You can then check for available updates:
dnf check-update
printf 'exit code: %s\n' "$?"dnf check-update commonly returns:
| Exit code | Meaning |
|---|---|
| 0 | No updates are available, or the check completed without finding any |
| 100 | Updates are available |
| 1 | An error occurred |
A return code of 100 is not a failed refresh. Scripts must handle it separately from a genuine repository error.
Common errors
- Refreshing one system and applying updates on another. Confirm the hostname before using
sudo. - Ignoring warnings about disabled or unreachable repositories. A partial repository view can produce an incomplete update plan.
- Confusing metadata refresh with installation.
apt updateanddnf makecache --refreshchange local indexes, not installed packages. - Running
dnf check-updatein a script withset -eand treating exit code 100 as a fatal error. - Editing repository files during an incident without recording the original configuration.
Exercise
Which command refreshes Debian/Ubuntu package lists, and which command forces a fresh dnf metadata download? What does neither command do?
Show answer
Use sudo apt update and sudo dnf makecache --refresh. Neither command installs package updates; both refresh local metadata used for later review.