How to fix to the ‘could not get lock’ error in Ubuntu

This post will show you how to fix the “could not get lock” or “unable to lock” error in Ubuntu.

Here is an example of this error when Ubuntu could not get a lock on the “/var/lib/dpkg/lock” resource:

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

In this example the error states that Ubuntu is unable to lock the administration directory:

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

The last example shows Ubuntu is unable to get a lock on the “/var/lib/apt/lists/” directory:

E: Unable to lock directory /var/lib/apt/lists/ 

What causes this error?

This error occurs when using the apt or apt-get command and:

  • it cannot get access to packages due to a broken internet connection (mid-install/update)
  • something else is installing or removing software

How to fix this error?

Step 1 – Find and stop the apt or apt-get process

Run the following command to kill all apt or apt-get processes:

sudo killall apt apt-get

This will show the process running apt or apt-get.

Step 2 – Delete the locks

Delete the locks if step 1 did not work:

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

What is a lock file?

Ubuntu uses lock files to prevent two or more processes from using the same data. Both apt and apt-get use lock files to prevent the processes from sharing data. Other operating systems like Windows does the same and will only allow you to add or remove a single program at a time. Lock issues occur when the previous apt or apt-get command did not terminate properly.

About the Authors

Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic!

Support the Cause

Support Anto Online and buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee

One Comment on “How to fix to the ‘could not get lock’ error in Ubuntu”

Leave a Reply

Your email address will not be published. Required fields are marked *