How to Fix “Could not get lock /var/lib/dpkg/lock” Error in Ubuntu

Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)

In this article we’ll cover the cause of the Could not get lock /var/lib/dpkg/lock – open (11 Resource temporarily unavailable) error, and two methods on how to solve it.

Why You’re Getting This Error

Whenever you want to install, build, remove or more generally manage packages in any Debian-based system, dpkg is what’s performing these tasks under the hood.

But you can only run one instance of the program at a time, and to ensure only one instance is running, the lock file is created and held by the server (this could be dpkg itself when manually managing packages).

The lock file is removed once the server successfully completes these operations and properly terminates.

This error arises when the lock file is present as a result of either a currently running process that is using dpkg, or an improperly terminated process that was using dpkg.

How To Fix This Error

As the cause of the problem splits into two in the first place, so does the solution, hence we have to differentiate between the possible causes first and here is how.

Method 1: Find and Wait For/Terminate Process Using dpkg

Find The Process Using dpkg

Step 1: Check if you have any applications like Software, Discover or Synaptic.

Step 2: Check if you have any running command that is installing, updating or removing a package like apt or dpkg itself.

Step 3: Check running processes that are using dpkg (or exactly the lock file) by executing the next commands.

sudo fuser /var/lib/dpkg/lock

word image 75
word image 76

If there is an output for the command then there is a running process that is using dpkg.

If you found any application, terminal window or process, then you know that there is a running app that uses dpkg, else means that an application was using dpkg and it was terminated improperly.

Terminate Process Using dpkg

If there is an application, a terminal window or a process; you are better off waiting for that to be completed properly, once done the problem will vanish, but if you have to terminate such an application without its completion for a plausible reason you can use this command:

sudo fuser /var/lib/dpkg/lock

Then take the number (the id of the process) at the end of this line and execute the next command:

sudo kill <ps_id>

word image 77

Or simply use this command with the process name:

sudo killall <ps_name>

word image 78

But your problem will be due to the second reason now.

Method 2: Remove The Lock File

If no application was using dpkg resource, or you already terminated such an application:

Remove the lock file (you have to make sure no app is using dpkg, check the kill commands above):

sudo rm /var/lib/dpkg/lock

Reconfigure dpkg:

sudo dpkg – configure -a

word image 79

Everything should be working by now. There are other issues like this one revolving around the existence of a lock file while trying to manage packages.

These can be solved using the same approach of making sure nobody is using that lock file, then removing it, then reconfiguring dpkg.

Another thing is you can reduce how often the system updates take place by opening the software & Updates application from your app menu (if you are using GNOME)

word image 80

Conclusion

In this tutorial, we learned how to fixCould not get lock /var/lib/dpkg/lock open (11 Resource temporarily unavailable)” error in Linux by using two methods. If you have any feedback or encountered any issues feel free to leave a comment and we’ll get back to you as soon as we can.

0 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)
0 Comments
Inline Feedbacks
View all comments
You May Also Like