Fix apt "Could not get lock /var/lib/dpkg/lock-frontend"
Find which process holds the dpkg lock, make apt wait for it, leave the lock file alone, and run dpkg --configure -a only after a run was truly interrupted.
If apt-get install ends with these two lines, another process is holding the package-management lock.
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 61492 (python3)E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?The output below was reproduced with a short python3 script (fcntl.lockf) holding lock-frontend for a few seconds, so the holder shows as (python3). On a real system the name is apt, dpkg, unattended-upgr or similar. Only a nonexistent package name was used, so nothing was installed.
[1] The PID in the error message is the holder. lsof or fuser show the same thing. fuser ships in the psmisc package, which a minimal install may not have.
# lsof /var/lib/dpkg/lock-frontendCOMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEpython3 61492 root 3wW REG 8,2 0 469814215 /var/lib/dpkg/lock-frontend# fuser -v /var/lib/dpkg/lock-frontend USER PID ACCESS COMMAND/var/lib/dpkg/lock-frontend: root 62320 F.... python3[2] If the holder looks like apt.systemd.daily or unattended-upgrade, it is the system's automatic update. Two timers run it each day.
# systemctl list-timers 'apt-daily*' --no-pagerNEXT LEFT LAST PASSED UNIT ACTIVATESMon 2026-10-19 19:01:43 KST 6h Mon 2026-10-19 09:33:48 KST 3h 22min ago apt-daily.timer apt-daily.serviceTue 2026-10-20 06:09:16 KST 17h Mon 2026-10-19 07:35:55 KST 5h 19min ago apt-daily-upgrade.timer apt-daily-upgrade.serviceapt-daily-upgrade.service runs /usr/lib/apt/apt.systemd.daily install (see systemctl cat).
[3] Wait. The lock releases by itself when the holder finishes, which makes waiting the safest fix. To avoid retyping, let apt wait with -o DPkg::Lock::Timeout=<seconds>. Result with 5 seconds:
# apt-get -o DPkg::Lock::Timeout=5 install gblab-no-such-packageWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 61492 (python3)...Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 61492 (python3)...E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?The waiting line appeared 5 times; only the first two are kept. The command exited with status 100 after 5 seconds. With -1 it waited until the lock was released and continued 6 seconds later. To wait out an automatic update, use something like -o DPkg::Lock::Timeout=300.
[4] Do not delete the lock file. Do not kill the PID. dpkg says so itself. This is dpkg --configure -a run while another process held the lock:
# dpkg --configure -adpkg: error: dpkg frontend lock was locked by another process with pid 63972Note: removing the lock file is always wrong, can damage the locked areaand the entire system. See <https://wiki.debian.org/Teams/Dpkg/FAQ#db-lock>.kill is a last resort, after you know who the holder is and that it is really stuck. A long wait alone is not a reason.
[5] Only when no process holds the lock (lsof prints nothing) and apt prints the message below, finish the interrupted dpkg run. The string is in libapt-pkg; it means an earlier run was cut off.
dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.man dpkg describes --configure as configuring "a package which has been unpacked but not yet configured", and -a (--pending) as doing so for all such packages. Then rerun the apt-get you started with.
# dpkg --configure -a