Lately, I ran into the error ‘Couldn’t get lock /var/lib/dpkg/lock’. In consequence, I might neither set up any packages nor replace the system. This error can also be carefully associated to the ‘Couldn’t get lock /var/lib/apt/lists/lock’ error. Right here’s some pattern output on Ubuntu 20.04.
Studying bundle lists… Finished
E: Couldn’t get lock /var/lib/apt/lists/lock. It’s held by course of 3620 (apt)
N: Bear in mind that eradicating the lock file isn’t an answer and will break your system.
E: Unable to lock listing /var/lib/apt/lists/
This may be fairly irritating and sometimes leaves you stranded, unable to replace, improve or set up any packages.
So, what causes this error?
Because the error suggests, this error often occurs when one other course of is at present utilizing the /var/lib/dpkg/lock or /var/lib/dpkg/lock file. Such occurs when you may have 2 or extra terminals working a system replace or improve. It may additionally happen once you prematurely cancel an replace/improve that’s in progress, by accident or in any other case. A second try to make use of apt or apt-get command will yield the error.
There’s completely no have to panic in case you run into this error. A few choices can be found to repair this subject. Let’s discover a few of the options.
Answer 1) Killing all processes that are utilizing the APT supervisor
Step one in diagnosing this downside is itemizing the processes which can be utilizing the apt bundle supervisor. To take action, use the ps command as proven:
$ ps aux | grep – i apt
Right here’s the output I obtained.
To clear the error, you have to kill the processes which can be related to the apt command. You are able to do so by sending a SIGKILL command to close down the method instantly. Execute the kill -9 command adopted by the method ID as follows.
$ sudo kill -9 3619
$ sudo kill -9 3620
As soon as executed, confirm once more if the processes have ended utilizing the ps command. If they’ve all cleared, you may proceed to replace the system with no downside.
Answer 2)
In some conditions, the foundation trigger might be the lock file. The lock file blocks two or a number of processes from accessing the identical knowledge. While you run any apt or apt-get command, a lock file is often created. Nevertheless, if the most recent apt command was not efficiently executed (i.e terminated abruptly), the lock file persists and blocks any subsequent apt or apt-get cases.
The answer to this downside is to eliminate the apt lock file(s). And it’s fairly simple. Merely run the command beneath:
$ sudo rm /var/lib/apt/lists/lock
If the error you might be getting is the ‘Couldn’t get lock /var/lib/dpkg/lock.’ error, delete the lock file as proven:
$ sudo rm /var/lib/dpkg/lock
Different occasions, you may get a /var/lib/dpkg/lock-frontend error. The lock-frontend error implies {that a} graphical utility that used apt / dpkg is at present working. This might both be Gdebi or synaptic bundle supervisor or another utility.
The speedy treatment is to exit or shut the appliance and provides it one other strive. If nothing offers, merely take away the /var/lib/dpkg/lock-frontend file as proven.
$ sudo rm /var/lib/dpkg/lock-frontend
Eradicating the lock-frontend file may once more result in the ‘Couldn’t get lock /var/lib/dpkg/lock’ error, so as soon as once more, you’ll have to take away the lock file.
$ sudo rm /var/lib/dpkg/lock
When you occur to get an error concerning the apt-cache lock comparable to /var/cache/apt/archives/lock, proceed and take away the lock file as proven.
$ sudo rm /var/cache/apt/archives/lock
$ sudo rm /var/lib/dpkg/lock
And that’s the way you resolve the ‘Couldn’t get lock /var/lib/dpkg/lock‘ and couldn’t get lock /var/lib/apt/lists/lock errors. I’m positive that when you’ve got come this far, it is best to have resolved the error by now. Tell us the way it went.
ps aux | grep -i apt,ubuntu 19.10 could not get lock,waiting for unattended-upgr to exit,apt.systemd.daily install,sudo dpkg –configure -a,unable to lock the administration library,grep –color=auto -i apt,configuring ttf-mscorefonts-installer,apt-get wait for lock,how to remove var lock,apt.systemd.daily lock_is_held install,frontend process ubuntu,ubuntu command frontend,"lock file is already taken, exiting",ubuntu unattended upgrade status,unattended-upgrade taking forever,fuser -vki /var/lib/dpkg/lock,ubuntu delete lock,fuser /var/lib/dpkg/lock,e: could not get lock /var/lib/dpkg/lock-frontend – open (11: resource temporarily unavailable),e: could not open lock file /var/lib/dpkg/lock-frontend – open (13: permission denied),waiting for cache lock could not get lock /var/lib/dpkg/lock-frontend,dpkg: error: dpkg frontend is locked by another process,unable to lock directory /var/lib/apt/lists/ kali linux,could not get lock /var/lib/dpkg/lock-frontend raspberry pi,sudo rm /var/lib/apt/lists/lock
