"Could not get lock /var/lib/dpkg/lock-frontend"
Another package operation holds the lock, or a previous one died and left it behind.
What you see
apt refuses to run, naming the lock file and often a PID. Sometimes it clears after a minute; sometimes it never does.
What is actually wrong
On a desktop or a freshly booted cloud instance it is almost always unattended-upgrades running in the background. If nothing is running, a previous apt was killed mid-transaction.
Codes and articles
Fixes (2)
Let the running operation finish
A process genuinely holds the lock. This is the right answer far more often than deleting the lock file.
See what holds it.
sudo lsof /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock /var/cache/apt/archives/lockIf it is unattended-upgrades, watch it and wait.
sudo tail -f /var/log/unattended-upgrades/unattended-upgrades.logKilling an in-flight dpkg transaction is what creates the much worse 'dpkg was interrupted' state in the other fix.
Confirm it has finished.
sudo lsof /var/lib/dpkg/lock-frontend || echo 'lock is free'If you routinely need apt immediately after boot, disable the timer rather than fighting the lock.
sudo systemctl disable --now apt-daily.timer apt-daily-upgrade.timer
sudo apt-get updateClear a stale lock and finish the interrupted transaction
Nothing holds the lock. Only do this once you have confirmed that with lsof — removing a live lock corrupts the package database.
Confirm again that nothing is running. This is the step people skip.
sudo lsof /var/lib/dpkg/lock-frontend; ps aux | grep -E '[a]pt|[d]pkg'Remove the stale locks.
sudo rm -f /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/cache/apt/archives/lock /var/lib/apt/lists/lockLet dpkg finish whatever it was part-way through.
sudo dpkg --configure -aThe lock is only the visible symptom. If a transaction was interrupted, packages are left half-configured and apt will keep failing until this completes.
Repair any broken dependencies left behind.
sudo apt-get install -fUpdate and confirm.
sudo apt-get update && sudo apt-get check
sudo apt-get check && echo OKRelated faults
Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.