Sub topic 9
Holding Packages with `apt-mark` and `dnf versionlock`
This chapter assumes you can use a Linux shell with sudo, identify the package manager on a server, and read basic package and service status. A package hold or version lock is a temporary exception to normal updating. Use one when an update would break compatibility, while you wait for a vendor fix or test a newer application version.
Why hold a package?
Routine patching normally updates all eligible packages. A hold prevents one package from changing during that process.
Common reasons include:
- An application supports only one database-client version.
- A kernel module has not been tested with a newer kernel.
- A vendor requires a specific library version.
- You need time to test an update before deploying it widely.
A hold reduces immediate change, but it also leaves the package without future bug and security fixes. Record the reason, owner, date and review condition for every hold.
| System family | Package tool | Hold or lock command | Release command |
|---|---|---|---|
| Debian or Ubuntu | `apt` and `dpkg` | `apt-mark hold PACKAGE` | `apt-mark unhold PACKAGE` |
| RHEL 8 or 9 | `dnf` and `rpm` | `dnf versionlock add PACKAGE` | `dnf versionlock delete PACKAGE` |
Hold a package with `apt-mark`
First inspect existing holds. Then add the package to the hold list:
apt-mark showhold
sudo apt-mark hold nginx
apt-mark showhold
apt-cache policy nginxapt-mark hold changes the package selection recorded by dpkg. Normal apt upgrade operations should leave nginx at its installed version. apt-mark showhold lists packages currently held.
Release the package when the compatibility problem is resolved:
sudo apt-mark unhold nginx
apt-mark showhold
sudo apt update
apt list --upgradableThe package can now appear as an available upgrade again. Review the pending version before installing it.
Lock a package with `dnf versionlock`
On RHEL-family systems, install the versionlock plugin if it is not already installed:
sudo dnf install python3-dnf-plugin-versionlock
sudo dnf versionlock add nginx
dnf versionlock list
sudo dnf upgradeThe lock records the installed package version and prevents normal dependency resolution from selecting a different nginx version. The command does not update the package while creating the lock.
Remove the lock after testing:
sudo dnf versionlock delete nginx
dnf versionlock list
dnf check-updateA version lock is usually stored in the DNF configuration area. Treat it as configuration that must be included in your server records or configuration-management system.
Important differences and failure modes
The two mechanisms apply at different layers. apt-mark hold changes a dpkg package selection state. dnf versionlock uses a DNF plugin to constrain package versions during dependency solving.
Neither mechanism should be assumed to freeze the entire dependency tree. Other packages may still change, and a package may be removed if dependency rules require it. Before a production run, simulate or review the transaction:
sudo apt-get --simulate upgrade
sudo dnf upgrade --assumenoDo not leave a hold in place merely because it is forgotten. After every patch window, compare the hold or lock list with your change records.
Exercise
You hold nginx on an Ubuntu server because a module is incompatible with the newest release. What should you do before the next patch window?
Show answer
Confirm the hold is still documented and justified, check security advisories for nginx, test the compatible module version, and remove the hold when the tested upgrade is ready.