---
title: "Fix Warning: Waiting for Transaction Lock on /var/lib/rpm/.rpm.lock"
description: "Learn how to resolve the RPM transaction lock error that prevents package installation and management on Linux systems."
date: 2025-06-27
categories: ["vps"]
tags: ["linux"]
---

Seeing this error when running `yum` or `dnf`?

```sh
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
```bash
sudo pkill -9 -f 'dnf|yum|rpm'
```

### Step 2: Remove lock files
```bash
sudo rm -f /var/lib/rpm/.rpm.lock
sudo rm -f /var/cache/dnf/metadata_lock.pid
```

### Step 3: Rebuild RPM database (if needed)
```bash
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:
```bash
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

```bash
rpm -qa | head -5
sudo yum update
```

## Prevention

1. Don't run multiple package commands at once
2. Check what's running before starting:
   ```bash
   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:
```bash
sudo journalctl -xe | grep -E 'yum|dnf|rpm'
ls -la /var/lib/rpm/
```