Another apt/dpkg process is mid-run — usually unattended-upgrades doing its job. Killing it blindly is how you create the bigger problem.
Ubuntu auto-applies security updates in the background; the lock is legitimately held for minutes.
Crash left dpkg half-configured; the next run needs cleanup before anything else.
ps aux | grep -E 'apt|dpkg' | grep -v grep
watch -n5 'ps aux | grep unattended'
sudo dpkg --configure -a && sudo apt -f install
sudo fuser -k /var/lib/dpkg/lock-frontend # only if ps shows nothing
On cloud VMs, cloud-init also runs apt at first boot. Give a fresh instance five minutes before concluding anything is broken.
An apt/dpkg process mid-operation — often an unattended-upgrades background run on Ubuntu. lsof /var/lib/dpkg/lock-frontend names the holder; waiting beats killing, since interrupting dpkg mid-write leaves the package database inconsistent.
Only after confirming the holder is dead (crashed, not running). Deleting the lock while dpkg is mid-operation corrupts package state; prefer killing the stale process or rebooting. Check for a dangling dpkg --configure -a afterwards.
Our most-documented failures, packaged as ready-to-ship starter kits: Docker, Kubernetes, and Terraform.
Browse the template store →One-time. Yours to modify. Instant download from the NinjaOps template store.