I've been getting a lot of "Could not get lock /var/lib/dpkg/lock" errors when"Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)" 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:
[[Edit]] For newer Ubuntu releases, this message has changed, and it now shows which process is holding the "/var/lib/dpkg/lock-frontend", like this:
Just like the message says, this could happen if another process is using If no processes are using 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 (from my experience, this usually happens if the system was forcefully shut down or rebooted while installing or upgrading packages, e.g. due to a power outage), you can remove the apt lock / lock-frontend file and see if that fixes the issue on your Ubuntu / Debian / Linux Mint (and any system that uses APT) system:
If you're still getting errors about either the
A package reconfiguration may also be needed after this, as well as fixing any potentially broken packages:
In some rare cases you may see an error like the one below, after
trying to run
In such cases, remove the offending file, then run the
Hopefully after running these commands you should stop getting the "Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)" and "Could not get lock /var/lib/dpkg/lock-frontend - open (11 Resource temporarily unavailable)" errors. Edit: one major reason for this error reoccurring seems to be the fact that Ubuntu enables unattended updates by default, and either an upgrade is currently in progress when you're seeing this error (in which case you should wait until the upgrade is performed successfully!), or an upgrade failed, in which case you're left with this error until you fix it. You could disable automatic (unattended) upgrades, see: How To Stop Installing Updates Automatically On Ubuntu Or Debian (Unattended Upgrades). |