How to fix E: Unable to lock directory /var/lib/apt/lists/ in APT

APTINTERMEDIATEHIGHUpdated Dec 29, 2025· 314 views

The apt package manager cannot acquire a lock on the /var/lib/apt/lists/ directory, usually because another apt process is running or a previous operation didn't complete properly. This prevents you from running package manager commands.

Quick fix

Fixes E: Unable to lock directory /var/lib/apt/lists/

ps aux | grep apt
  1. Wait for automatic updates to complete
  2. Use fuser to safely terminate lock-holding processes
  3. Force-kill stubborn processes if needed
  4. Remove stale lock files (last resort)
apt — error
ps aux | grep apt
E: Unable to lock directory /var/lib/apt/lists/

What this error means

When you run apt commands like `apt update`, `apt install`, or `apt upgrade`, the package manager creates lock files in /var/lib/apt/lists/ to prevent multiple processes from corrupting the package database simultaneously. If a lock file already exists and the process that created it is still running (or didn't clean up properly), apt will refuse to proceed with new operations. This error is a safety mechanism that protects your system from broken package states. However, it can occur when: - An automatic background update is still running (apt.systemd.daily) - A previous apt command was interrupted or crashed - Another package manager (like Ubuntu Software Center) is actively running - Lock files weren't properly released due to a system issue

Typical symptoms

  • apt commands fail immediately with the lock directory error
  • You cannot run apt update, apt install, or apt upgrade
  • The error appears when trying to install or update packages via the command line
  • Other package managers (Software Center, Synaptic) may show similar errors

Common causes

  1. Another apt process (including apt.systemd.daily automated updates) is currently running and holding the lock
  2. A previous apt command was interrupted or crashed without releasing the lock file
  3. Ubuntu Software Center, Synaptic, or another package manager is currently open or running
  4. Stale lock files remain from a system shutdown or reboot during a package operation

How to fix "E: Unable to lock directory /var/lib/apt/lists/"

1Wait for automatic updates to complete

First, check if the system's automatic update daemon is running. It runs periodically and will release the lock when finished.

bash
ps aux | grep apt

If you see apt.systemd.daily in the output, the automatic update is running. Simply wait a few minutes for it to complete, then try your command again.

2Use fuser to safely terminate lock-holding processes

If another apt process is stuck or not responding, use fuser to safely terminate it. This is the recommended approach as it's more controlled than killing processes directly.

bash
sudo fuser -vik -TERM /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock

This command will:
- Identify which processes are holding these lock files
- Prompt you to confirm termination
- Send a TERM signal (graceful shutdown) to those processes

After this completes, try your apt command again.

3Force-kill stubborn processes if needed

If the graceful termination doesn't work, use the -KILL signal for a forceful shutdown:

bash
sudo fuser -vik -KILL /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock

After terminating the processes, reconfigure the package system:

bash
sudo dpkg --configure -a
sudo apt update

The first command reconfigures any interrupted package operations.

4Remove stale lock files (last resort)

If the above approaches don't work and you're confident no apt process is running, you can manually remove lock files:

bash
sudo rm /var/lib/apt/lists/lock
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/cache/apt/archives/lock

After removing the locks, reconfigure the package system:

bash
sudo dpkg --configure -a
sudo apt update

Note: Only do this as a last resort when you're certain no package manager process is running, as manually deleting lock files can lead to package database corruption if processes are still active.

5Restart your system if all else fails

If lock files persist even after checking for running processes, a system restart will clear them:

bash
sudo reboot

After reboot, the lock files will be cleaned up and you can run apt commands normally. This is a safe recovery option when lock files are truly stale.

Advanced notes

Lock files exist for a reason: they prevent simultaneous access to the package database that could corrupt your system. Never blindly delete them without understanding the consequences. The fuser approach is preferred because it safely terminates the problematic processes while respecting process shutdown procedures. If you frequently encounter this error on servers, consider implementing systemd-hold or apt-listchanges to prevent automatic updates at inconvenient times. On systems with SELinux, ensure proper context is set on /var/lib/apt/ and /var/lib/dpkg/ directories after any permission issues.

Frequently asked questions

What does "E: Unable to lock directory /var/lib/apt/lists/" mean?
When you run apt commands like apt update, apt install, or apt upgrade, the package manager creates lock files in /var/lib/apt/lists/ to prevent multiple processes from corrupting the package database simultaneously. If a lock file already exists and the process that created it is still running (or didn't clean up properly), apt will refuse to proceed with new operations. This error is a safety mechanism that protects your system from broken package states.
How do I fix "E: Unable to lock directory /var/lib/apt/lists/"?
The apt package manager cannot acquire a lock on the /var/lib/apt/lists/ directory, usually because another apt process is running or a previous operation didn't complete properly. This prevents you from running package manager commands.
What causes "E: Unable to lock directory /var/lib/apt/lists/"?
Another apt process (including apt.systemd.daily automated updates) is currently running and holding the lock A previous apt command was interrupted or crashed without releasing the lock file Ubuntu Software Center, Synaptic, or another package manager is currently open or running
Is the "E: Unable to lock directory /var/lib/apt/lists/" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading