Solved : E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)

If you are trying to install some package on Ubuntu and by some means, in middle of the installation, some unexpected things happens causing installation to abort in the middle, in similar situation if you try to install the same package later on, you may see an error like below,

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?

If you see the lock file using “file /var/lib/dpkg/lock” command, its an empty file, but used as a lock to avoid multiple installations simultaneously.

Solution : To remove this error, we need to manually remove this file as,

$ sudo rm -rf /var/lib/dpkg/lock

Now, if you try to install the same or any other package again, you will not see the above error and installation happens successfully.

This above solution will also work for below error,

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

The Another way to fix this error is identify which process is using this lock and kill the process. For example, in our case apt.systemd.daily was busy doing something by acquiring the lock. In this, you either wait for the process to complete, so lock will get released automatically or go on killing the process as,

$ ps -ax | grep lock
   33 ?        I<     0:00 [kblockd]
 2418 ?        S      0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held update
 3939 ?        S      0:00 flock --nonblock /run/mlocate.daily.lock /usr/bin/ionice -c3 /usr/bin/updatedb.mlocate
 4056 pts/2    S+     0:00 grep --color=auto lock
$ sudo kill -9 2418

Here, 2418 is the process ID of the process which had acquired the lock.

Leave a Comment