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

2 min




This tutorial would help you to fix the error could not get lock or unable to lock the administration directory in Ubuntu.

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?

While performing any command line operation using apt, due to certain reasons (e.g. unable to retrieve some packages from server, or your internet connection broke down mid-way or due to some other issues) if the apt process abruptly ends, then your system may ran into the above errors. It means the apt process couldn’t complete and now you won’t be able to use any other apt commands unless you fix it.

There are multiple ways to fix this, let’s try one by one.

Fix 1

This fix to find out the process IDs of the apt processes and trying to kill them. Run below commands from the terminal:

ps aux | grep apt

It will list all the apt processes which is holding the lock. In below example, you can see the process IDs (first column) which are holding the lock.

kill -9 processnumber

 

After the above command, reboot and try to perform any apt command which gave you error. This should resolve the error.

If you still facing the error and Fix 1 did not solve it, follow below fixes.

Fix 2

Try below command from the terminal, this would try to stop the apt service.

sudo systemctl stop apt-daily.timer

After above command, try whether you are still facing the error. If it resolves it, then reboot the system and make sure to start the service afterwards via below:

sudo systemctl start apt-daily.timer

If Fix 2 did not work, follow below fix.

Fix 3

WARNING:
Below fix is dangerous and should be tried only when above Fix 1 and Fix 2 did not work and it is a last resort for you. This can cause a broken system if operated carelessly.

Run below commands from terminal. This would remove the lock files manually via root privilages.

sudo fuser -cuk /var/lib/dpkg/lock; sudo rm -f /var/lib/dpkg/lock
sudo fuser -cuk /var/cache/apt/archives/lock; sudo rm -f /var/cache/apt/archives/lock

After running above commands, try to perform your operation which got you the error. This should solve it.

 

☞ Whatever system you are running in Ubuntu and its derivatives, any of the above three fix should work. Comment below if it did or didn’t solve your problem.





Arindam

Creator of debugpoint.com. All time Linux user and open-source supporter. Connect with me via Telegram, Twitter, LinkedIn, or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x