How To Fix "Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)" Errors

E: Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

I've been getting a lot of "Could not get lock /var/lib/dpkg/lock" errors when trying to install or upgrade packages from the command line on Ubuntu virtual machines lately, so I thought I'd make a post about how you can get rid of such issues.

This is the complete 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?

Just like the message says, this could happen if another process is using /var/lib/dpkg/lock. So the first thing to do if you encounter this error is to make sure you close package managers such as Synaptic, etc. Also check if you have other open terminals that are currently running an install / upgrade and wait for those processes to finish.

If no processes are using /var/lib/dpkg/lock, the next step is to... wait. In some cases, this is enough to fix such "Could not get lock /var/lib/dpkg/lock" errors.

Another potential way to get around this issue is to reboot the system and see if this still occurs.

There are cases though in which the solutions mentioned above may not be enough. For such cases, here's what you can do. 

Only use this if nothing else worked! Using the commands below may result in broken packages / corruption. Use them at your own risk!

If nothing else worked, you can remove the apt lock file and see if that fixes the issue on your Ubuntu / Debian / Linux Mint (and any system that uses APT) system:

sudo rm /var/lib/apt/lists/lock

If you're still getting errors about either the apt cache lock (/var/cache/apt/archives/lock) or the dpkg lock (/var/lib/dpkg/lock), you can remove them:

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

A package reconfiguration may also be needed after this, as well as fixing any potentially broken packages:

sudo dpkg --configure -a
sudo apt install -f

Hopefully after running these commands you should stop getting the "Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)" error.

No comments:

Powered by Blogger.