Home Bugs (Software and Hardware) Fixing E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable) error in Kali Linux

Fixing E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable) error in Kali Linux

by blackMORE
Fixing E Could not get lock var lib dpkg lock - open 11 Resource temporarily unavailable error in Kali Linux - blackMORE Ops

I just reinstalled Kali Linux in my PC and after my first logon, I tried to run apt-get update and had E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) error coming up. Interesting, because I am the only user (I just installed the system) and there’s no other process using dpkg. This was pretty annoying as it stops you from installing updates or new softwares. Here’s a run down of the issues:

“E: Could not get lock /var/lib/dpkg/lock” error

This happens when I tried to use apt-get update

root@kali:~# apt-get update
Hit http://http.kali.org sana InRelease       
Hit http://security.kali.org sana/updates InRelease
.
.
Hit http://security.kali.org sana/updates/non-free amd64 Packages              
Fetched 9,334 kB in 2min 18s (67.5 kB/s)                                       
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?

Fixing E Could not get lock var lib dpkg lock - open 11 Resource temporarily unavailable error in Kali Linux - blackMORE Ops

Trying to fix the error

Tried multiple steps

Try 1 – Rebooting:

At this point I tried restart and see if that makes any differences. It didn’t.

Try 2: – try with sudo

I tried using sudo to see if this was related with this other error dpkg: warning: ‘ldconfig’ not found in PATH or not executable.

root@kali:~# sudo apt-get update
Hit http://http.kali.org sana InRelease                                   
.
.
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?

sudo didn’t fix it.

Try 3 – Try Googling

Like some search results returned, I tried to delete lock file

root@kali:~# rm /var/cache/apt/archives/lock

Then update

root@kali:~# apt-get update
.
.
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?

Nope still no luck.

Try 4 – Actually read the error!

Then I actually read the freaking error which I didn’t do till now. Duh, the error is:

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?

Which indicates that the lock file is in /var/lib/dpkg/lock folder. Silly me! So let’s have a look into /var/lib/dpkg/ folder to confirm is there is really a lock file in there?

root@kali:~# rm /var/lib/dpkg/
alternatives/   diversions-old  parts/          status-old
available       info/           statoverride    triggers/
diversions      lock            status          updates/

There is a lock file. So let’s delete that.

root@kali:~# rm /var/lib/dpkg/lock

and then try to update again

root@kali:~# apt-get update
Hit http://security.kali.org sana/updates InRelease
.
.
Reading package lists... Done                                                  
root@kali:~#

Booyaa. Worked just fine. Well, ofc it does, when you can write and read properly!!!!

Now just to be on safe side, let’s do an apt-get upgrade

root@kali:~# apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  armitage gr-osmosdr iceweasel john john-data libgnuradio-osmosdr0.1.3
  libgnutls-deb0-28 libgnutls-openssl27 libsnmp-base libsnmp-perl libsnmp30
  openvas python-hpack python-impacket python-pyperclip snmp snmpd
17 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/70.6 MB of archives.
After this operation, 12.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Reading changelogs... Done
Preconfiguring packages ...
(Reading database ... 323261 files and directories currently installed.).
.
.
root@kali:~#

Yeah .. working well. and finally finish it with installing gimp.

root@kali:~# apt-get install gimp
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  gimp-data libamd2.3.1 libbabl-0.1-0 libcamd2.3.1 libccolamd2.8.0
  libcholmod2.1.2 libcolamd2.8.0 libgegl-0.2-0 libgimp2.0 libopenraw1
  libumfpack5.6.2
Suggested packages:
  gimp-help-en gimp-help gimp-data-extras
The following NEW packages will be installed:
  gimp gimp-data libamd2.3.1 libbabl-0.1-0 libcamd2.3.1 libccolamd2.8.0
  libcholmod2.1.2 libcolamd2.8.0 libgegl-0.2-0 libgimp2.0 libopenraw1
  libumfpack5.6.2
0 upgraded, 12 newly installed, 0 to remove and 0 not upgraded.
Need to get 15.7 MB of archives.
After this operation, 70.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://http.kali.org/kali/ sana/main libamd2.3.1 amd64 1:4.2.1-3 [26.3 kB]
.
.
Fetched 15.7 MB in 2min 37s (99.8 kB/s)                                                                                                                                                                           
Selecting previously unselected package libamd2.3.1:amd64.
(Reading database ... 323276 files and directories currently installed.)
.
.
Processing triggers for libc-bin (2.19-18) ...
Processing triggers for menu (2.1.47) ...
root@kali:~#

Perfect.

Moral of this post

Sometimes it really helps when you actually read the error and not just follow Google search results blindly. Same applies to my posts, use your judgment, 9 out of 10, you’re probably bang on the money.

You may also like

23 comments

Prakash Khadka August 17, 2015 - 9:34 pm

view the process

lsof /var/lib/dpkg/lock

kill it

kill [PID]

Reply
kogik August 28, 2018 - 7:20 am

thaks!

Reply
aklys August 19, 2015 - 12:51 pm

Love this being stated. We are so used to rushing into things and not thinking for ourselves. When largely if we slow down take account of things the answers can become apparent and are simpler than we first consider.

Reply
Sierra Juliet June 8, 2016 - 8:12 am

Anyone who has spent enough time behind these computers knows it is just faster to find a solution someone else discovered then to burn the midnight oil trying to resolve issues sometimes. This of course leads to us sometimes feeling dumb for not having read things more carefully. It happens to the best of us.

Reply
janne lukkarinen September 18, 2015 - 7:59 pm

LoL i feel smited first response ctrl+c next google ctrl+v end up here see read actual error look back in terminal Facepalm

Reply
Tizeng Yan December 1, 2015 - 5:43 pm

you just saved me buddy!

Reply
Stephanie M. Davis (@StephanieMDavis) June 29, 2016 - 9:47 am

EXCELLENT; this solution worked impeccably. Insightful comments too! Thanks to all.

Reply
Thomas Phillips August 22, 2016 - 2:10 pm

Thank you for this. “4 – Actually read the error!” is some of the best advice ever lol.

Reply
Dishant Sheth December 4, 2016 - 7:03 pm

Try using this as a last resort
You can delete the lock file with the following command:

sudo rm /var/lib/apt/lists/lock

You also need to delete the lock file in the cache directory:

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

Reply
G3rR4r February 18, 2018 - 6:15 am

thanks very much sir….

Reply
ravi April 24, 2017 - 8:05 pm

excellent … thnq for the solution::

Reply
sneha July 7, 2017 - 4:56 pm

cool thankx..

Reply
hardik August 26, 2017 - 8:55 pm

fire only sudo apt-get dist-upgrade -y –fix-missing in terminal.

Reply
Muhammad Ary November 14, 2017 - 10:02 am

i m not work,,help me

Reply
Leon Guerrero November 18, 2017 - 1:10 am

what actually caused this “lock: file to be created?

Reply
ggdfdfdsf December 29, 2017 - 7:48 am

ur such an amazing person, thank you!

Reply
Darkshadow March 19, 2018 - 12:23 am

Thank you so much for this article.

Reply
anonymous83 November 23, 2018 - 11:50 am

this was really helpful. thank you :)

Reply
ajay January 21, 2019 - 8:18 pm

same error showed but couldn’t rectify it till now
I tried rm /var/lib/dpkg/
but it showed cannot remove directory

Reply
de February 19, 2019 - 12:32 am

use rm /var/lib/dpkg/lock
do not try to delete the whole dpkg directory

Reply
esic January 31, 2019 - 7:09 pm

fixed my issue tanks

Reply
Michael Nation April 14, 2019 - 7:08 am

Thanks, this fixed my problem too. (Actually it was apt-get upgrade that wouldn’t run.) But it’s a little scary because there’s no info about what the lock file is, why it was there, and whether it was really safe to just blithely delete it.

Reply
harry-18 February 16, 2020 - 9:25 pm

thanks bro . it helped me:)

Reply

Leave a Reply to Dishant ShethCancel reply

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