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

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.

23 comments

  1. view the process

    lsof /var/lib/dpkg/lock

    kill it

    kill [PID]

  2. 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.

    • 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.

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

  4. you just saved me buddy!

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

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

  7. 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

  8. excellent … thnq for the solution::

  9. cool thankx..

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

  11. i m not work,,help me

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

  13. ur such an amazing person, thank you!

  14. Thank you so much for this article.

  15. this was really helpful. thank you :)

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

  17. fixed my issue tanks

  18. 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.

  19. thanks bro . it helped me:)

Leave your solution or comment to help others.

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

Discover more from blackMORE Ops

Subscribe now to keep reading and get access to the full archive.

Continue reading

Privacy Policy on Cookies Usage

Some services used in this site uses cookies to tailor user experience or to show ads.