Sub topic 6
Applying Updates: `upgrade`, `full-upgrade`, and `dnf upgrade`
Assume you can use a Linux shell, sudo, and a test Debian/Ubuntu or RHEL-family server. You also need refreshed repository metadata before reviewing or installing updates.
Updating a server has two separate steps:
- Find the versions available in configured repositories.
- Resolve dependencies and install selected packages.
apt and dnf usually protect you from unsafe dependency changes, but they make different choices when an update requires packages to be added or removed.
Debian and Ubuntu: `apt upgrade`
First refresh the package index. The package index is the local list of package versions and repository information.
sudo apt update
apt list --upgradable
sudo apt upgradeapt upgrade installs available newer versions without removing currently installed packages. It can install new dependencies when needed, but it leaves packages back if completing an update would require removing another package.
Review the proposed changes before confirming. Pay attention to packages marked for removal, held packages, and services that may restart. To preview the transaction without changing the system, use:
sudo apt upgrade --simulateThe option is also called --dry-run in many apt commands.
When to use `apt full-upgrade`
apt full-upgrade may remove or replace packages when that is necessary to complete the dependency solution. This is common during kernel transitions, library transitions, or changes in package organization.
sudo apt full-upgradeUse it deliberately. A removal is not automatically dangerous, but you should understand why an important service or metapackage is being removed. If the proposed action is unexpected, answer N, capture the output, and investigate before retrying.
| Command | Typical behavior | Main caution |
|---|---|---|
| `apt upgrade` | Avoids removals while upgrading | Some packages may remain back |
| `apt full-upgrade` | May add and remove packages to finish upgrades | Review removals carefully |
| `dnf upgrade` | Resolves dependencies and applies updates | Check transaction changes |
RHEL-family systems: `dnf upgrade`
On RHEL, Rocky Linux, AlmaLinux, Fedora, and related systems, dnf upgrade refreshes repository metadata as needed, resolves dependencies, and installs newer packages.
sudo dnf upgradeThe command displays the transaction summary before it changes anything. Review packages to be installed, upgraded, downgraded, or removed. To inspect available updates first:
dnf check-update
echo "exit code: $?"dnf check-update returns 100 when updates are available, 0 when none are available, and another nonzero code for an error. Therefore, exit code 100 is an expected result, not necessarily a failure.
Unlike the conservative default of apt upgrade, dnf upgrade normally performs the dependency changes required by the solver. A kernel update may install a new kernel while retaining older kernels for recovery. Do not remove the older kernel until the new one has been tested.
After either package operation, inspect the transaction output and check affected services:
systemctl --failed
sudo systemctl status ssh --no-pagerUse the service name appropriate for your server. A package update can complete successfully while a service fails to start because of a configuration or compatibility problem.
Exercise
Which command should you choose when apt upgrade leaves packages back because completing the update requires dependency changes?
Show answer
Review the proposed transaction and use sudo apt full-upgrade if the required additions and removals are acceptable. Use apt upgrade when avoiding removals is more important.