Programming, tutorials, mechatronics, operating systems, and other tech stuff

How to fix "error Could not get lock /var/lib/dpkg/lock resource temporarily unavailable" in ubuntu

No comments
Often when we do the apt commands, whether it be to install, update, or uninstall/remove. We'll likely encountered a problem, ranging from a mere trivial to an annoying error which makes it impossible to continue the process. One of the most common error message is:

[code lang="bash"] E: Could not get lock/var/lib/dpkg/lock-open (11 Resource be temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it? [/code]

Generally this is because we forcibly stop or interrupt the process when performing the apt-get command. Usually with Ctrl + C or interrupt (halt). It causes the process to suddenly stop and the apt didn't manage to open the lock that prevents the apt process from running simultaneously.

Basically, the apt is not allowed to run more than one process, because it can mess up the dependencies. So it requires a lock to make sure that there is only 1 process running. When we run the command apt, apt will then automatically create a lock, and when we try to run another apt command, the apt will check if there is a lock, if any, then the second apt process will stop and display the error message above.

Sometimes, when the apt process is forced to stop or interrupted (halt), the process had not previously delete the apt lock. So the apt command we try to run will recognize that there is an apt processes running, despite there isn't. And in the end, the apt will terminate with error.

The fix is pretty easy, we just need to remove the lock manually. But to do so, we need root privileges.
Just with the command:

[code lang="bash"] sudo rm/var/lib/apt/lists/lock [/code] or

[code lang="bash"] sudo rm/var/cache/apt/archives/lock [/code]

Then try to run apt-get command again.
well, that's it. easy isn't it?

I hope this helps anyone.

No comments :

Post a Comment