Linux  ·  low  ·  Core system faults

"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

E: Could not get lockdpkg/lock-frontenddpkg was interrupted

Fixes (2)

Let the running operation finish
Shell5–20 minuteslow riskreversible

A process genuinely holds the lock. This is the right answer far more often than deleting the lock file.

  1. See what holds it.

    Shell
    sudo lsof /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock /var/cache/apt/archives/lock
  2. If it is unattended-upgrades, watch it and wait.

    Shell
    sudo tail -f /var/log/unattended-upgrades/unattended-upgrades.log

    Killing an in-flight dpkg transaction is what creates the much worse 'dpkg was interrupted' state in the other fix.

  3. Confirm it has finished.

    Shell
    sudo lsof /var/lib/dpkg/lock-frontend || echo 'lock is free'
  4. If you routinely need apt immediately after boot, disable the timer rather than fighting the lock.

    Shell
    sudo systemctl disable --now apt-daily.timer apt-daily-upgrade.timer
Confirm it workedapt runs.
Shell
sudo apt-get update
If you need to undo itRe-enable the timers with systemctl enable --now if you disabled them.
Clear a stale lock and finish the interrupted transaction
Shell as root15 minutesmedium risknot reversible

Nothing holds the lock. Only do this once you have confirmed that with lsof — removing a live lock corrupts the package database.

  1. Confirm again that nothing is running. This is the step people skip.

    Shell
    sudo lsof /var/lib/dpkg/lock-frontend; ps aux | grep -E '[a]pt|[d]pkg'
  2. Remove the stale locks.

    Shell
    sudo rm -f /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/cache/apt/archives/lock /var/lib/apt/lists/lock
  3. Let dpkg finish whatever it was part-way through.

    Shell
    sudo dpkg --configure -a

    The lock is only the visible symptom. If a transaction was interrupted, packages are left half-configured and apt will keep failing until this completes.

  4. Repair any broken dependencies left behind.

    Shell
    sudo apt-get install -f
  5. Update and confirm.

    Shell
    sudo apt-get update && sudo apt-get check
Confirm it workedapt-get check reports no broken packages.
Shell
sudo apt-get check && echo OK
If you need to undo itNone. If dpkg --configure -a cannot complete, the specific package it names usually has to be reinstalled or force-removed.

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.