Resource Usage & CloudLinux Limits

Managing DNF/YUM Version Locks on CloudLinux & RHEL-Based Systems: A Complete Guide

By the Domain India teamPublished 6 min read
Knowledge base article
Contents (11 sections)

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.

Key takeaways

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.

Own server only

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.

bash
# AlmaLinux, Rocky Linux, RHEL and CloudLinux 8 and 9
dnf install python3-dnf-plugin-versionlock

CentOS 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

bash
dnf versionlock list

Example output:

text
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:

bash
dnf versionlock add ea-apache24

To lock a specific version, give the full name, version, release and architecture. Find the exact string first:

bash
rpm -q ea-apache24
dnf versionlock add ea-apache24-2.4.63-2.el8.cloudlinux.x86_64

To block one specific bad version but allow everything else, use an exclude entry instead:

bash
dnf versionlock exclude mysql-community-server-8.0.38-1.el8

Check the result with dnf versionlock list, then run dnf check-update to confirm the package no longer appears.

5. Remove a version lock

  1. Remove the lock for one package: dnf versionlock delete ea-apache24.
  2. Or remove every lock at once: dnf versionlock clear.
  3. Confirm with dnf versionlock list, which should no longer show the package.
  4. 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.

bash
dnf install at
systemctl enable --now atd
echo "/usr/bin/dnf versionlock delete ea-apache24" | at now + 30 days
atq    # list pending jobs

Fixed 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.

bash
# /etc/cron.d/unlock-apache  (note the user field)
0 3 25 8 * root /usr/bin/dnf versionlock delete ea-apache24

Conditional 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.

bash
#!/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"
fi

Run 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.

Ready when you are

Get cPanel hosting from ₹125/mo + GST

See plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app
DNF Version Locks on AlmaLinux and Rocky | Domain India