E: Could not get lock /var/lib/dpkg/lock-frontend — how to fix
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 2481 (unattended-upgr)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
Quick fix: Wait a few minutes: it's usually unattended-upgrades or another apt window. Check with ps aux | grep -E 'apt|dpkg'. If no apt process is running at all, run sudo dpkg --configure -a.
What it means
Only one package manager can change the system at a time. The lock is held by another process, named in the message (unattended-upgr = automatic security updates, apt, apt-get, packagekitd = Software Center).
Fix 1: wait
On a freshly booted machine, automatic updates often run for a few minutes. Wait and watch:
ps aux | grep -E '[a]pt|[d]pkg'
# or wait until the lock is free:
while sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do sleep 5; done
Close other terminals running apt and the Software Updater GUI.
Fix 2: the other process is stuck
If the process has been running for a long time with no CPU or disk activity, stop it gracefully:
sudo kill <PID> # PID from the message
Then repair any interrupted installation:
sudo dpkg --configure -a
sudo apt -f install
Don't delete the lock files first
Removing /var/lib/dpkg/lock* while another process is really writing can corrupt the package database. Only if no apt/dpkg process exists (ps shows nothing) and the error remains after a reboot, remove the stale locks and repair:
sudo rm /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/cache/apt/archives/lock
sudo dpkg --configure -a
In scripts and cloud-init
Wait for the lock instead of failing. apt has a built-in option:
sudo apt-get -o DPkg::Lock::Timeout=300 install -y nginx
Last updated 2026-10-27.