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 of 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 do the same and will only allow you to add or remove a single program at a time. Lock issues occurred when the previous apt or apt-get command did not terminate properly.