Troubleshoot "Could not get lock /var/lib/dpkg/lock" errors when trying to update or install debian packages
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?
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
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...