Sub topic 2
Seeing what is pending before you change anything
This chapter assumes you can use a Linux shell with sudo, that you know a package repository is a server that hosts software packages, and that you have SSH access to a test machine. Run these commands on a test machine first.
Seeing what is pending
Refresh the package index before you look at updates. The index is the list of package versions that each repository offers. If it is stale, the list of pending updates is wrong.
Debian and Ubuntu
sudo apt update
apt list --upgradableRHEL-family systems
dnf check-update
echo "exit code: $?"dnf check-update exits with 100 when updates are available and 0 when none are. Use the exit code in scripts.
| Task | apt (Debian, Ubuntu) | dnf (RHEL-family) |
|---|---|---|
| Refresh the index | `sudo apt update` | `dnf check-update` (also refreshes) |
| List pending updates | `apt list --upgradable` | `dnf check-update` |
flowchart TD
A["Refresh the index"] --> B["List pending updates"]
B --> C{"Anything listed?"}
C -->|No| D["Stop: nothing to apply"]
C -->|Yes| E["Read the list, then apply"]caption: Review loop before any change alt: A flowchart showing that you refresh the index, list pending updates, and then either stop when nothing is listed or read the list before applying.
Applying updates
apt upgrade installs newer versions of packages you already have. It never removes a package. If an update needs a new dependency, that package is held back. apt full-upgrade also adds or removes packages when an update needs it, so read its plan before you confirm.
sudo apt upgrade
sudo apt full-upgradeOn RHEL-family systems, dnf upgrade installs newer versions and removes obsolete packages when required. Read the transaction summary before you accept it.
sudo dnf upgradeSecurity-only updates
dnf
List the pending security advisories, then install only those fixes.
dnf updateinfo list --security
sudo dnf upgrade --securityDebian and Ubuntu
Debian and Ubuntu do not have a single security-only command. Security updates come from a separate suite such as bookworm-security or noble-security. Filter the pending list for those names.
apt list --upgradable 2>/dev/null | grep -i securityInstall the security updates by name, or let unattended-upgrades apply them automatically.
Deciding when a reboot or restart is needed
A kernel or core library update does not affect running programs until they restart or the machine reboots. Check after each patch run.
# Debian and Ubuntu
if [ -f /var/run/reboot-required ]; then
echo "Reboot required"
cat /var/run/reboot-required.pkgs 2>/dev/null
fi
# RHEL-family (needs the dnf-plugins-core package)
sudo dnf needs-restarting -r
echo "exit code: $?"On RHEL-family systems, needs-restarting -r exits with 1 when a reboot is recommended and 0 when it is not. For a single service, restart only the services that use the updated library.
::: callout note Restarting a service drops its active connections. Schedule restarts in a maintenance window. :::
Exercise
Exercise
On a Debian system, /var/run/reboot-required exists after a patch run. What should you do first?
Show answer
Find out which packages need the reboot by reading /var/run/reboot-required.pkgs, then schedule a reboot or restart the affected services in a maintenance window.