How to fix dpkg: error: dpkg status database is locked by another process in APT
This error occurs when apt or dpkg is locked by another package manager process, typically one that is stuck or running in the background. Fix it by identifying the blocking process, terminating it, and reconfiguring dpkg.
Quick fix
Fixes dpkg: error: dpkg status database is locked by another process
ps aux | grep -i apt- Check if an apt process is currently running
- Identify which process holds the lock
- Gracefully terminate the blocking process
- Remove stale lock files (if process is confirmed dead)
ps aux | grep -i aptdpkg: error: dpkg status database is locked by another process
What this error means
The dpkg package manager uses lock files to prevent concurrent package operations from corrupting the database. When this error appears, it means another process is holding one of these locks (usually /var/lib/dpkg/lock or /var/lib/dpkg/lock-frontend). This commonly happens when a previous package operation was interrupted, crashed, or is still running in the background. The lock file is a safety mechanism—removing it without stopping the blocking process can damage your system.
Typical symptoms
- apt or apt-get commands fail to run
- Package installation or update operations hang
- Error appears when trying to install, upgrade, or remove packages
- Automated system updates fail in background
- CI/CD pipelines fail during package installation steps
Common causes
- A previous apt/dpkg operation was interrupted and left a process running
- An automated package update is running in the background (apt-daily)
- Another package manager (snap, apt, apt-get, dpkg) is actively installing packages
- A stalled package operation crashed but did not release the lock
- Two package manager instances were started simultaneously (race condition)
How to fix "dpkg: error: dpkg status database is locked by another process"
First, see if there are any active apt processes:
ps aux | grep -i aptIf you see active apt processes, wait for them to finish naturally. If you see only your grep command, proceed to the next step.
Use lsof to find the process holding the lock:
sudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/dpkg/lock-frontendNote the PID (Process ID) if one is returned. If no process is listed, the lock file may be stale.
If a process was found, kill it gracefully:
sudo kill PIDWait a few seconds. If the process doesn't terminate, force kill it:
sudo kill -9 PIDAlternatively, kill all stuck apt processes:
sudo pkill -9 apt
sudo pkill -9 apt-getOnce the blocking process is confirmed stopped, remove the lock files:
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/cache/apt/archives/lockWarning: Only remove lock files after confirming the blocking process is terminated. Removing them while a process is still running can corrupt your package database.
After removing locks, reconfigure dpkg to finish any pending operations:
sudo dpkg --configure -aThen update the package list:
sudo apt updateYou can now resume normal package operations.
If the above steps don't work, a system reboot will release all locks:
sudo rebootThis is the safest option if you're unsure about process termination. After reboot, dpkg will be in a clean state.
Advanced notes
On Ubuntu systems, automatic background updates via apt-daily can trigger this error. To prevent it, disable automatic updates by editing /etc/apt/apt.conf.d/20auto-upgrades and setting:
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";The Debian team strongly advises against simply removing lock files—always terminate the blocking process first. Lock files prevent corruption of the dpkg status database, which is critical to system stability. Container environments (Docker, Kubernetes) may need to handle stale locks in entrypoint scripts before running package operations.
Frequently asked questions
- What does "dpkg: error: dpkg status database is locked by another process" mean?
- The dpkg package manager uses lock files to prevent concurrent package operations from corrupting the database. When this error appears, it means another process is holding one of these locks (usually /var/lib/dpkg/lock or /var/lib/dpkg/lock-frontend). This commonly happens when a previous package operation was interrupted, crashed, or is still running in the background.
- How do I fix "dpkg: error: dpkg status database is locked by another process"?
- This error occurs when apt or dpkg is locked by another package manager process, typically one that is stuck or running in the background. Fix it by identifying the blocking process, terminating it, and reconfiguring dpkg.
- What causes "dpkg: error: dpkg status database is locked by another process"?
- A previous apt/dpkg operation was interrupted and left a process running An automated package update is running in the background (apt-daily) Another package manager (snap, apt, apt-get, dpkg) is actively installing packages
- Is the "dpkg: error: dpkg status database is locked by another process" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.