Connecting via SSH

How to Version Lock RPM Packages in Linux

By the Domain India teamPublished 7 min read
Knowledge base article
Contents (14 sections)

A version lock stops the package manager from upgrading (or downgrading) a package, so a known-good version stays installed while the rest of the system updates. This guide shows how to lock, list and release packages with dnf on current RHEL-family systems, with notes for older yum systems, openSUSE and Debian or Ubuntu. It applies to a server you administer yourself, such as a VPS; on shared hosting the server's packages are managed for you.

Key takeaways

On AlmaLinux, Rocky Linux, RHEL and Fedora, install the versionlock plugin if needed, then run sudo dnf versionlock add PACKAGE to pin the installed version, sudo dnf versionlock list to see locks, and sudo dnf versionlock delete PACKAGE to release one. On openSUSE use zypper addlock; on Debian and Ubuntu use apt-mark hold. Lock as little as possible and review locks regularly, because a locked package also misses its security fixes.

1. When a version lock makes sense

Good reasons to lock
  • An application is certified or tested against one exact version of a runtime or database
  • A new release has a known bug and you are waiting for the fix
  • You want updates to happen on your schedule, one package at a time
Costs to keep in mind
  • A locked package receives no security updates until you release it
  • Locks can block other updates that depend on a newer version
  • Forgotten locks leave servers quietly out of date

Lock a specific package for a specific reason, write the reason down, and set a date to review it.

2. dnf: AlmaLinux, Rocky Linux, RHEL 8 and later

dnf is the package manager on every supported RHEL-family release. Locking needs the versionlock plugin:

bash
sudo dnf install 'dnf-command(versionlock)'

That installs the right plugin package for your release (python3-dnf-plugin-versionlock on RHEL 8 to 10 and their rebuilds).

Lock a package

bash
# Lock the version that is installed now
sudo dnf versionlock add nginx

# Lock a specific version (use the full name-version-release)
sudo dnf versionlock add mariadb-server-10.11.*

To find the exact version string first, run rpm -q nginx or dnf list --showduplicates nginx.

List locks

bash
sudo dnf versionlock list

Each line shows a locked package pattern, for example nginx-1:1.26.3-1.el9.*.

Release a lock

bash
sudo dnf versionlock delete nginx     # one package
sudo dnf versionlock clear            # every lock

Block a version instead of pinning one

If you only want to avoid one bad release but allow others, use exclude:

bash
sudo dnf versionlock exclude nginx-1.27.0*

The locks are stored in /etc/dnf/plugins/versionlock.list, a plain text file you can review or keep in version control.

Fedora 41 and later

Fedora now ships DNF5, where versionlock is built in. The commands are the same (dnf versionlock add, list, delete, clear), so no plugin is needed.

3. Test before you rely on a lock

  1. Add the lock
    as above.
  2. Preview updates
    with sudo dnf check-update or sudo dnf upgrade --assumeno. The locked package should not be offered.
  3. Watch for dependency problems.
    If dnf upgrade reports that another package needs a newer version of the locked one, decide whether to lock that package too or release the lock.
  4. Record the lock
    with the reason and a review date, for example in a comment in your change log.

4. Locking a whole module stream

On RHEL 8 and 9, some software such as PHP, Node.js and some databases come as module streams. Enabling a stream (for example sudo dnf module enable nodejs:22) already keeps you on that major version while still allowing its security updates. That is often a better choice than pinning an exact package version. Module streams are being phased out in RHEL 10 in favour of separately named packages, so check your release's documentation.

5. yum on older systems

CentOS 7 and RHEL 7 use yum and have reached end of life, so they no longer receive public updates. If you still manage one, the plugin is yum-plugin-versionlock and the commands mirror dnf:

bash
sudo yum install yum-plugin-versionlock
sudo yum versionlock add httpd
sudo yum versionlock list
sudo yum versionlock delete httpd

Plan a move to a supported release such as AlmaLinux or Rocky Linux; a lock is no substitute for security updates.

6. openSUSE and SUSE Linux Enterprise

zypper has locking built in:

bash
sudo zypper addlock nginx        # lock
sudo zypper locks                # list
sudo zypper removelock nginx     # release

A zypper lock prevents the package from being installed, removed or changed at all, not only upgraded.

7. Debian and Ubuntu

These systems use apt rather than RPM, but the idea is the same:

bash
sudo apt-mark hold nginx         # hold at the installed version
apt-mark showhold                # list held packages
sudo apt-mark unhold nginx       # release

For finer control, such as preferring one version from a specific repository, use an APT pin file under /etc/apt/preferences.d/.

8. Good practice

  • Lock the smallest set. Lock the one package that matters, not everything it depends on, unless updates prove you must.
  • Don't lock the kernel for long. Kernel updates carry important security fixes. If you need a specific kernel, set it as the default boot entry and keep the lock short.
  • Review monthly. Run dnf versionlock list as part of routine maintenance and release locks you no longer need.
  • Automated updates respect locks. Tools such as dnf-automatic skip locked packages, which is the point, but it also means those packages are never patched automatically.
  • Snapshot before big changes. Take a snapshot or backup before releasing a long-standing lock and upgrading.

9. Running this on Domain India

Version locks are a server-admin tool. On Domain India shared hosting (cPanel, DirectAdmin, Webuzo) the server's packages are managed for every account on it, and you can't install or lock system packages; choose your PHP version in the control panel instead.

A Domain India VPS is self-managed with full root access, so you run dnf and manage locks yourself. The VPS page lists AlmaLinux and Rocky Linux among the operating systems offered, and VPS plans include automated snapshots, which are useful before you release a lock and upgrade. Prices on the card are live and exclude 18% GST.

VPS Starter
₹552.65/mo + GST
  • 1 vCPU
  • 2 GB DDR4 RAM
  • 64 GB NVMe SSD Storage
  • 2 TB Monthly Bandwidth
See plan details
How do I lock a package version with dnf?

Install the plugin with sudo dnf install 'dnf-command(versionlock)', then run sudo dnf versionlock add followed by the package name. That pins the version installed now. Use sudo dnf versionlock list to see locks and sudo dnf versionlock delete to release one.

Where does dnf store version locks?

In /etc/dnf/plugins/versionlock.list, a plain text file with one locked package pattern per line.

Does a version lock stop security updates?

Yes. A locked package is not updated at all, including security fixes. Keep locks few and short, and review them regularly.

What is the Ubuntu or Debian equivalent of versionlock?

Use sudo apt-mark hold followed by the package name to hold it, apt-mark showhold to list held packages, and sudo apt-mark unhold to release it.

Can I lock packages on shared hosting?

No. On shared hosting the server's packages are managed for every account, and customers can't install or lock system packages. Version locks are for a server you administer, such as a VPS.

Is yum-plugin-versionlock still used?

Only on CentOS 7 and RHEL 7, which have reached end of life. Current RHEL-family releases use dnf, with the dnf versionlock plugin or DNF5's built-in command on Fedora.

Ready to run your own server? Compare VPS plans, or open a support ticket if you are unsure whether a VPS or shared hosting fits your project.

Get a VPS with full root access

Choose your Linux distribution and manage packages, updates and locks your way.

See VPS plans

Ready when you are

Get VPS from ₹552.65/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
How to Version Lock RPM Packages in Linux (DNF)