Skip to content

Instantly share code, notes, and snippets.

@JPvRiel
Created February 16, 2017 10:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPvRiel/e10e318ea817043b2d2038792046ca46 to your computer and use it in GitHub Desktop.
Save JPvRiel/e10e318ea817043b2d2038792046ca46 to your computer and use it in GitHub Desktop.
Troubleshoot "Could not get lock /var/lib/dpkg/lock" errors when trying to update or install debian packages

Troubleshoot "Could not get lock /var/lib/dpkg/lock" errors when trying to update or install debian packages

Error Message

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

Troubleshoot

Find out if a process has locked the file

$ sudo lsof /var/lib/dpkg/lock
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
aptd    4667 root    8uW  REG  252,3        0 131210 /var/lib/dpkg/lock

Anothe less precise way is to look for a likely process still running

$ ps -e | grep -E '(apt)|(dpkg)'
 4667 ?        00:00:01 aptd

Get details on the process

$ sudo ps -p 4667 -f 
UID        PID  PPID  C STIME TTY          TIME CMD
root      4667     1  0 12:12 ?        00:00:01 /usr/bin/python3 /usr/sbin/aptd

aptd

Find out more about this package

$ apt-file search /usr/sbin/aptd
aptdaemon: /usr/sbin/aptd

The aptdeamon package allows non-root users to check for and apply package updates, so it's often likely an open or crashed package manager/update tool could have triggered aptdaemon to lock the file.

TODO: look for graceful ways to stop or restart aptdaemon, and find out what its busy doing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment