apt refuses to run because another process holds the dpkg lock
Your error
Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (unattended-upgr)2 more lines it can showFix it fast
Most common cause, 1 of 3unattended-upgrades is installing security updates
Let the run finish; it releases the lock when it exits.
sudo apt-get -o DPkg::Lock::Timeout=600 install -y nginx
# optional, for short-lived machines:
sudo systemctl edit apt-daily.timer # add [Timer] Persistent=false
sudo systemctl edit apt-daily-upgrade.timerShort answer
Unable to acquire the dpkg frontend lock, is another process using it? means another package manager is running right now. On Ubuntu that is usually unattended-upgrades, cloud-init on a fresh VM, or a second apt or packagekitd. Let it finish, or make apt wait with -o DPkg::Lock::Timeout=600. Never delete the lock file. Applies to apt 2.8 and 3.x.
Which cause do you have?
The message already names the PID and, in brackets, the process name. Look at that process, how long it has run and what started it; the name and the parent tell the three causes apart.
ps -o pid,ppid,etime,cmd -p 1234Then find the line you see in this list and open its fix:
- 1unattended-upgrades is installing security updates
The process in brackets is unattended-upgr, often right after the machine boots - 2cloud-init is still installing packages on a new instance
The holder is apt-get or dpkg, its parent chain leads to cloud-init, and the server was created minutes ago - 3You or a tool started a second apt, dpkg or software updater
The holder is apt, apt-get, dpkg or packagekitd, started from another terminal, a desktop updater or an automation task
What does the error look like?
Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (unattended-upgr)Be aware that removing the lock file is not a solution and may break your system.Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
Cause 1 of 3
unattended-upgrades is installing security updates
You seeThe process in brackets is unattended-upgr, often right after the machine boots
Check
In this case the dpkg frontend lock belongs to Ubuntu's automatic updates. The apt-daily.timer and apt-daily-upgrade.timer units start them on a schedule, and when the machine was off at that time the timer fires soon after the next boot, which is exactly when people log in and run apt.
systemctl status apt-daily.service apt-daily-upgrade.service --no-pagerFix
Let the run finish; it releases the lock when it exits. For scripts, ask apt to wait for the lock instead of failing at once. On VM images that only start for short jobs, Ubuntu's guide suggests Persistent=false in an override of the timers so a missed run is not caught up at boot.
sudo apt-get -o DPkg::Lock::Timeout=600 install -y nginx
# optional, for short-lived machines:
sudo systemctl edit apt-daily.timer # add [Timer] Persistent=false
sudo systemctl edit apt-daily-upgrade.timerVerify
apt-get prints Waiting for cache lock while the update runs, then installs the package once the lock is free.
systemctl is-active apt-daily-upgrade.serviceConfirmed by documentation.ubuntu.com
Cause 2 of 3
cloud-init is still installing packages on a new instance
You seeThe holder is apt-get or dpkg, its parent chain leads to cloud-init, and the server was created minutes ago
Check
If the lock holder descends from cloud-init, the instance's user data is still being applied. Its package module can update, upgrade and install packages through apt during the first boot, so provisioning scripts that start right away collide with it.
cloud-init status --longFix
Block until cloud-init has finished before the first apt command in your provisioning or CI step.
cloud-init status --wait
sudo apt-get install -y nginxVerify
cloud-init status reports done, and the apt command runs without the lock error.
cloud-init statusConfirmed by docs.cloud-init.io
Cause 3 of 3
You or a tool started a second apt, dpkg or software updater
You seeThe holder is apt, apt-get, dpkg or packagekitd, started from another terminal, a desktop updater or an automation task
Check
apt takes these locks as fcntl record locks, and the kernel releases such a lock when the process that holds it ends. So the lock files being present on disk is normal; the error only means a live process has them. Two shells, two automation tasks or a desktop software updater using apt at the same moment produce exactly this.
ps -o pid,etime,cmd -C apt,apt-get,dpkg,packagekitdFix
Wait for the other command or close the updater, then run yours. Do not remove /var/lib/dpkg/lock-frontend or /var/lib/dpkg/lock; apt itself warns that this may break the system. If a dpkg run was killed halfway, apt later asks for dpkg --configure -a, which is a separate repair.
# wait for the other process to end, then:
sudo apt-get update
sudo apt-get install -y nginxVerify
The command runs to the end with no lock error.
sudo apt-get checkConfirmed by salsa.debian.org
How do I stop it coming back?
- Put -o DPkg::Lock::Timeout=600 on every apt-get call in provisioning scripts and CI runners, so a scheduled update makes them wait instead of fail.
- Start first-boot automation with cloud-init status --wait on cloud images.
- Run package steps one at a time per host in your automation tool, never as two background jobs on the same machine.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.