A version lock pins a package at a known version so that dnf update cannot replace it. This guide shows how to install the versionlock plugin, list, add and remove locks, and schedule an unlock safely on AlmaLinux, Rocky Linux, RHEL and CloudLinux 8 and 9.
Install the plugin with dnf install python3-dnf-plugin-versionlock. Lock the installed version with dnf versionlock add PACKAGE, see locks with dnf versionlock list, and remove them with dnf versionlock delete PACKAGE or dnf versionlock clear. Locks are stored in /etc/dnf/plugins/versionlock.list. To unlock later, schedule a one-off at job rather than a cron line, and compare versions with sort -V, never with a plain string comparison.
These commands need root on your own server, such as a VPS. They don't apply to Domain India shared hosting, where the server is managed for you.
1. Why lock a package version
- To stop an update from breaking a working application, for example a PHP, MySQL or Apache build your site depends on.
- To keep a known good version of a critical package while you test the new one.
- To delay an upgrade until a fix or compatibility statement is published.
A lock is a temporary safety measure. A package that stays locked also stops receiving security fixes, so keep a note of every lock and the reason for it.
2. Install the versionlock plugin
The versionlock command comes from a plugin that is not always installed.
# AlmaLinux, Rocky Linux, RHEL and CloudLinux 8 and 9
dnf install python3-dnf-plugin-versionlockCentOS 7 and CloudLinux 7 used yum and the yum-plugin-versionlock package. CentOS 7 is end of life and no longer receives security updates, so plan a move to AlmaLinux or Rocky Linux if you still run it.
3. List locked packages
dnf versionlock listExample output:
mysql-community-server-0:8.0.37-1.el8.*
ea-apache24-1:2.4.63-2.el8.cloudlinux.*The same entries are kept in /etc/dnf/plugins/versionlock.list, which is useful to back up or review.
4. Add a version lock
The simplest form locks the version that is currently installed:
dnf versionlock add ea-apache24To lock a specific version, give the full name, version, release and architecture. Find the exact string first:
rpm -q ea-apache24
dnf versionlock add ea-apache24-2.4.63-2.el8.cloudlinux.x86_64To block one specific bad version but allow everything else, use an exclude entry instead:
dnf versionlock exclude mysql-community-server-8.0.38-1.el8Check the result with dnf versionlock list, then run dnf check-update to confirm the package no longer appears.
5. Remove a version lock
- Remove the lock for one package:
dnf versionlock delete ea-apache24. - Or remove every lock at once:
dnf versionlock clear. - Confirm with
dnf versionlock list, which should no longer show the package. - Update the package when you are ready:
dnf update ea-apache24.
6. Schedule an unlock
One-off unlock after 30 days, with at
at runs a command once and then forgets it, which suits a temporary lock.
dnf install at
systemctl enable --now atd
echo "/usr/bin/dnf versionlock delete ea-apache24" | at now + 30 days
atq # list pending jobsFixed date, with cron
A cron line such as the one below runs every year on 25 August at 03:00, not just once. Remove it after it has run, or use at instead.
# /etc/cron.d/unlock-apache (note the user field)
0 3 25 8 * root /usr/bin/dnf versionlock delete ea-apache24Conditional unlock when a newer version exists
The original version of this script compared versions as plain text and searched for the word "available" in output that does not contain it, so it never worked. The script below fixes both problems. It also asks dnf to ignore the lock while checking, because a locked package hides newer versions from dnf list.
#!/bin/bash
set -euo pipefail
PACKAGE="ea-apache24"
LOCKED_VERSION="2.4.63"
# Newest version in the repositories, ignoring the lock
AVAILABLE=$(dnf -q --disableplugin=versionlock list --available --showduplicates "$PACKAGE" 2>/dev/null \
| awk -v p="$PACKAGE" '$1 ~ "^"p"\\." {print $2}' \
| sed 's/^[0-9]*://' | sort -V | tail -n 1)
if [[ -z "$AVAILABLE" ]]; then
echo "No available version found for $PACKAGE"
exit 0
fi
NEWEST=$(printf '%s\n%s\n' "$LOCKED_VERSION" "$AVAILABLE" | sort -V | tail -n 1)
if [[ "$NEWEST" != "$LOCKED_VERSION" ]]; then
echo "Newer $PACKAGE available: $AVAILABLE"
dnf versionlock delete "$PACKAGE"
dnf -y update "$PACKAGE"
fiRun it weekly from cron, for example 0 4 * * 1 root /root/check-unlock.sh in /etc/cron.d/. On a production server it is often safer to have the script send you an email instead of updating automatically, so you can test the new version first.
7. Good practice
- Lock critical packages before a major system update, and remove the lock once you have tested the new version.
- Record every lock with a date and a reason, for example in a comment next to your backup of
versionlock.list. - Review locks monthly. A forgotten lock silently blocks security updates.
- On cPanel servers, packages starting with
ea-belong to EasyApache. Lock them only if you understand the dependencies between them, or the next EasyApache update may fail.
If you want a server where you control package versions yourself, see VPS plans compared.
Frequently asked questions
Why does dnf versionlock say the command is not found?
The plugin is not installed. Install python3-dnf-plugin-versionlock on version 8 or 9 systems, then run the command again.
Does a version lock stop security updates?
Yes. A locked package is not updated at all, including for security fixes, so keep locks short and review them regularly.
Where are version locks stored?
In /etc/dnf/plugins/versionlock.list. Each line is a package pattern; dnf versionlock list shows the same entries.
Why does my script never see a newer version of a locked package?
The versionlock plugin hides other versions of a locked package. Add --disableplugin=versionlock to the dnf list command that checks for updates.
Can I lock packages on Domain India shared hosting?
No. Shared hosting servers are managed for you, and package versions are set by our team. Version locks are for servers where you have root access, such as a VPS.
If you need help with package locks on your server, open a support ticket or use our 24/7 live chat.