Fix Warning: Waiting for Transaction Lock on /var/lib/rpm/.rpm.lock

Learn how to resolve the RPM transaction lock error that prevents package installation and management on Linux systems.

Fix Warning: Waiting for Transaction Lock on /var/lib/rpm/.rpm.lock

Seeing this error when running yum or dnf?

warning: waiting for transaction lock on /var/lib/rpm/.rpm.lock

Another package process is running, or a previous one crashed and left a lock file behind. Here’s how to fix it.

What Causes This

  1. Concurrent operations - Multiple yum/dnf commands running
  2. Crashed processes - Previous install/update was interrupted
  3. Stale locks - System crash left lock files behind

The Fix

Step 1: Kill stuck processes

sudo pkill -9 -f 'dnf|yum|rpm'

Step 2: Remove lock files

sudo rm -f /var/lib/rpm/.rpm.lock
sudo rm -f /var/cache/dnf/metadata_lock.pid

Step 3: Rebuild RPM database (if needed)

mkdir /var/lib/rpm/backup
cp -a /var/lib/rpm/__db* /var/lib/rpm/backup/
rm -f /var/lib/rpm/__db.[0-9][0-9]*
rpm --rebuilddb
yum clean all

Quick Fix (No Database Rebuild)

If you just need to clear the lock:

sudo pkill -9 -f 'dnf|yum|rpm'
sudo rm -f /var/lib/rpm/.rpm.lock
sudo rm -f /var/cache/dnf/metadata_lock.pid

Verify It Worked

rpm -qa | head -5
sudo yum update

Prevention

  1. Don’t run multiple package commands at once
  2. Check what’s running before starting:
    ps aux | grep -E 'yum|dnf|rpm'
  3. Use Ctrl+C to stop, don’t kill -9
  4. Keep automated scripts from overlapping

Still Broken?

Check logs:

sudo journalctl -xe | grep -E 'yum|dnf|rpm'
ls -la /var/lib/rpm/