VOOZH about

URL: https://www.tecmint.com/fix-unable-to-lock-the-administration-directory-var-lib-dpkg-lock/

⇱ Fix "Unable to lock the administration directory (/var/lib/dpkg/)" in Ubuntu


Skip to content

While using the apt-get command or the relatively new APT package management tool in Ubuntu Linux or its derivatives such as Linux Mint (which I actually use as my primary operating system for doing daily work), you might have encountered the error – “unable to lock the administration directory (/var/lib/dpkg/) is another process using it” on the command line.

This error can be so annoying especially for new Linux (Ubuntu) users who may not know exactly the cause of the error.

Below is an example, showing the lock file error in Ubuntu 16.10:

tecmint@TecMint:~$ sudo apt install neofetch
[sudo] password for tecmint:
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?

The output below is another possible instance of the same error:

E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/ 
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?

How can you solve the above error in case you bump into it in the future? There are several ways of dealing with this error(s), but in this guide, we will go through the two easiest and probably the most effective ways of solving it.

1. Find and Kill all apt-get or apt Processes

Run the command below to generate a list of all processes whose name comprises of the word apt, you will get a list inclusive of all apt or apt-get processes by using ps and grep commands together with a pipeline.

$ ps -A | grep apt
👁 Find apt and apt-get Processes
Find apt and apt-get Processes

For each apt-get or apt process that you can see in the output of the command above, kill each process using the command below.

The process ID (PID) is found in the first column from the screenshot above.

$ sudo kill -9 processnumber
OR
$ sudo kill -SIGKILL processnumber

For instance, in the command below where 9 is the signal number for the SIGKILL signal, will kill the first apt process:

$ sudo kill -9 13431
OR
$ sudo kill -SIGKILL 13431

2. Delete the lock Files

A lock file simply prevents access to another file(s) or some data on your Linux system, this concept is present in Windows and other operating systems as well.

Once you run an apt-get or apt command, a lock file is created under the any of these directories /var/lib/apt/lists/, /var/lib/dpkg/ and /var/cache/apt/archives/.

This helps to avoid the apt-get or apt process that is already running from being interrupted by either a user or other system processes that would need to work with files being used by apt-get or apt. When the process has finished executing, the lock file is then deleted.

Important: In case a lock is still exiting in the two directories above with no noticeable apt-get or apt process running, this may mean the process was held for one reason or the other, therefore you need to delete the lock files in order to clear the error.

First execute the command below to remove the lock file in the /var/lib/dpkg/ directory:

$ sudo rm /var/lib/dpkg/lock

Afterwards force package(s) to reconfigure like so:

$ sudo dpkg --configure -a

Alternatively, delete the lock files in the /var/lib/apt/lists/ and cache directory as below:

$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/cache/apt/archives/lock

Next, update your packages sources list as follows:

$ sudo apt update
OR
$ sudo apt-get update

In conclusion, we have walked through two important methods to deal with a common problem faced by Ubuntu (and its derivatives) users, while running apt-get or apt as well as aptitude commands.

Do you have any other reliable methods to share meant for deal with this common error? Then get in touch with us via the feedback form below.

In addition, you may as well want to learn how to find and kill running processes and read through a simple guide to kill, pkill and killall commands to terminate a process in Linux.

If this article helped, share it with someone on your team.
TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

101 Comments

Leave a Reply
  1. In the parrot os terminal whenever I try to update using sudo apt-get update it shows a lot of errors I don’t know what to do a lot of Ign:1, and Ign:2 coming up again, and again can you help me how to solve the problem?

    Reply
    • @Hari,

      The Ign means the package version information is avoided due to a file retrieval error or version mismatch.

      Reply
  2. Is there any biggest problem because of the “unable to lock the administration directory (/var/lib/dpkg/” of this error in the system?

    Reply
    • @Hari,

      You can’t run the apt command to install or remove packages from the system until the error is fixed…

      Reply
  3. I just used:

    $ sudo dpkg --configure -a
    

    and it worked for me…

    Reply
  4. Cool is working for me, here is short story

    root@pc-02:/home/user1# apt-get remove && apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    0 upgraded, 0 newly installed, 0 to remove and 767 not upgraded.
    Reading package lists… Done
    E: Could not get lock /var/lib/apt/lists/lock – open (11: Resource temporarily unavailable)
    E: Unable to lock directory /var/lib/apt/lists/

    $ sudo rm /var/lib/dpkg/lock

    Afterward force package(s) to reconfigure like so:

    $ sudo dpkg --configure -a

    $ sudo apt-get remove && apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y

    :) all best

    Reply
    • @znpz/feasn

      Nice! Thanks a lot for the useful feedback.

      Reply
  5. Thanks. Really helpful for us as first time learn Linux.

    Reply
  6. You truly are a god amongst men, sir. I thank you dearly.

    Reply
  7. Thanks, It worked for me

    Reply
  8. Great post, thanks!

    Ran into issue

    fatal: [192.168.56.xxx]: FAILED! => {“changed”: false, “msg”: “‘/usr/bin/aptitude safe-upgrade’ failed: E: Could not open lock file /var/lib/dpkg/lock – open (13: Permission denied)\nE: Unable to lock the administration directory (/var/lib/dpkg/), are you root?\n”, “rc”: 255, “stdout”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nInitializing package states…\n”, “stdout_lines”: [“Reading package lists…”, “Building dependency tree…”, “Reading state information…”, “Initializing package states…”]}

    fatal: [192.168.56.xxx]: FAILED! => {“changed”: false, “msg”: “‘/usr/bin/aptitude safe-upgrade’ failed: E: Could not open lock file /var/lib/dpkg/lock – open (13: Permission denied)\nE: Unable to lock the administration directory (/var/lib/dpkg/), are you root?\n”, “rc”: 255, “stdout”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nInitializing package states…\n”, “stdout_lines”: [“Reading package lists…”, “Building dependency tree…”, “Reading state information…”, “Initializing package states…”]}

    Reply
    • Get root sudo su then rm the file to resolve “Permission denied“. If still denied, chmod 777 then rm the file.

      $ sudo su
      $ chmod 777 /var/lib/dpkg/lock
      $ rm /var/lib/dpkg/lock
      

      Close the terminal window to drop back out of su.

      Reply
      • @J dog

        Many thanks for sharing this, we are grateful.

        Reply
    • @Tony

      Welcome, thanks for the feedback.

      Reply
  9. Thank you very much, I’m new to Ubuntu and almost about break the monitor.. You save it

    Reply
  10. the only useful document on the web thank you very much

    Reply
    • @jean

      Oh, great! We are glad that this worked for you. Thanks for the useful feedback.

      Reply
  11. Thalaiva …Super..!

    Reply
    • @Prasanth

      Great, thanks for the feedback.

      Reply
  12. Thanks a ton, it worked without errors for me..

    Reply
    • @kk

      Welcome, thanks for the useful feedback.

      Reply
  13. thanks a lot, this worked !!!

    Reply
    • @Dhanush

      Welcome, we are glad that it worked for you. Thanks for the feedback.

      Reply
  14. Dear Aaron,

    Thanks for your response, it helped me a lot, in my situation I am new to linux. It is a powerful technology for those who know how to use it.

    =)

    Reply
    • @Pablo

      Welcome and thanks for the feedback.

      Reply
  15. HI, i followed this procedure yesterday and it worked, but i am fcing the same problem today too. will i have to be doing this everyday, or there is a way i can stop it once and for all

    Reply
    • @Olivia

      This should not happen everyday, but in case it continues to happen, use the provided solutions.

      Reply
  16. Thank you so much. it is very easy to follow and understand

    Reply
    • @Olivia

      Welcome, many thanks for the feedback.

      Reply
  17. This article is so simple and easy to understand. Saved my day! Thanks Aaron!

    Reply
    • @Sneha

      Welcome, thanks a lot for the feedback.

      Reply
  18. Thank you so much Aaron Kili. You saved me. Thanks a lot.

    Reply
    • @Valli

      Welcome, thanks for the feedback.

      Reply
  19. Hi,

    I am trying for a long time to install Kali Linux from MS store but failed always, after running “sudo sh.xfce4.sh” command.

    When I run “sudo/etc/init.d/xrdp start” it says” No such file or directory not found

    Kindly guide

    Reply
  20. I am getting these errors..

    Err:1 http://in.archive.ubuntu.com/ubuntu artful InRelease
    Could not resolve 'in.archive.ubuntu.com'
    Err:2 http://in.archive.ubuntu.com/ubuntu artful-updates InRelease
    Could not resolve 'in.archive.ubuntu.com'
    Err:3 http://in.archive.ubuntu.com/ubuntu artful-backports InRelease
    Could not resolve 'in.archive.ubuntu.com'
    Err:4 http://archive.canonical.com/ubuntu artful InRelease
    Could not resolve 'archive.canonical.com'
    Err:5 http://security.ubuntu.com/ubuntu artful-security InRelease
    Could not resolve 'security.ubuntu.com'
    Reading package lists... Done
    W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/artful/InRelease Could not resolve 'in.archive.ubuntu.com'
    W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/artful-updates/InRelease Could not resolve 'in.archive.ubuntu.com'
    W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/artful-backports/InRelease Could not resolve 'in.archive.ubuntu.com'
    W: Failed to fetch http://archive.canonical.com/ubuntu/dists/artful/InRelease Could not resolve 'archive.canonical.com'
    W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/artful-security/InRelease Could not resolve 'security.ubuntu.com'
    W: Some index files failed to download. They have been ignored, or old ones used instead.

    Reply
    • @Ganesh

      Ensure that your device is connected to the internet. You can test using ping, try to ping google.com or any popular servers.

      Reply
  21. Hi Sir,

    0% [Connecting to in.archive.ubuntu.com (2001:67c:1360:8001:
    

    it is coming like this after typing given commands.

    Reply
    • @srujan

      What commands in particular, just be a little clear on the question so we can help you easily. Hope you have understood.

      Reply
  22. thanks brother, its working! I recently bought a vps and it had the same issue but now its fixed. Thank you :)

    Reply
    • @Manal

      Welcome, we are glad that you found this guide helpful. Thanks for the feedback.

      Reply
    • @lucky

      We are lucky to have you following us, thanks for the feedback.

      Reply
  23. Not able to update the python version from 2.7 to 3.6, it is showing error like this:

    $ sudo apt-get install python3.6Reading package lists... Done
    Building dependency tree 
    Reading state information... Done
    E: Unable to locate package python3.6
    E: Couldn't find any package by glob 'python3.6'
    E: Couldn't find any package by regex 'python3.6'
    
    Reply
  24. thank you brother

    Reply
    • @arjun

      Welcome, thanks for the feedback.

      Reply
  25. Thank you Aaron! it fixed on my machine

    Reply
    • @Yipeng

      We are glad that this worked well for you. Many thanks for the feedback.

      Reply
    • @bishal

      Ok, thanks for the feedback.

      Reply
  26. Thank for sharing! It’s very useful. Fixed my issue!

    Reply
    • @VNCoupon

      Oh, that’s great. We are glad to know this. Thanks for the feedback.

      Reply
  27. Hello, I have this issue too and it get fixed with this guide. But, the issue return each time the system startup. Any idea why is this happening?

    Reply
    • @Luis

      Try to use both approaches mentioned in the article, if they fail to work let us know, we will try to investigate.

      Reply
  28. Thanks a lot brother.

    Reply
    • @F-Society

      Welcome, thanks for the feedback.

      Reply
  29. Thank you brother for this wonderful article, fixed my issue..

    Reply
    • @Simon

      Welcome, thanks for the feedback.

      Reply
  30. Great help, I used the trick with debian 9, worked well. Thanks
    Idrissa

    Reply
    • @Idrissa

      Oh, that’s good. Many thanks for the feedback.

      Reply
    • @Trung

      Welcome, many thanks for the feedback.

      Reply
  31. Thank you .. it working nice and easy to follow ..

    Reply
    • @awati

      We are glad to know that this worked for you, many thanks for the feedback.

      Reply
  32. thanks sir , you are great

    Reply
  33. Your the best, thanks this solved my problem..

    Reply
    • @Nix

      Welcome, we are pleased to know that this helped you out. Thanks for the feedback.

      Reply
    • @henry

      Welcome, thanks for the feedback.

      Reply
  34. Superb!!!
    Thank you very much for the solution, it helped me alot.

    Reply
    • @Amol

      Okay, this is great. Am happy that this article helped you a lot. Thanks for the feedback.

      Reply
  35. Thanks a lot buddy it worked for me :)

    Reply
    • @Himanshu

      Welcome, thanks for the feedback.

      Reply
  36. Hi, I use Ubuntu 16.04, after i follow your step, the problem is solve but it come a new problem after input this command.

    $ sudo apt-get update..
    
    the problem is :
    E: Problem executing scripts APT::Update::Post-Invoke-Success 
    'if /usr/bin/test -w /var/cache/app-info -a -e /usr/bin/appstreamcli; 
    then appstreamcli refresh > /dev/null; fi'
    E: Sub-process returned an error code
    

    can you help me for solve this problem..?

    Reply
  37. you rock man, the 2nd command worked

    Reply
    • @KaliUser

      Am excited to know about this, thanks for the feedback.

      Reply
  38. Worked great! Thank you.

    Reply
    • @james

      That’s good to know. Thanks for the feedback.

      Reply
  39. Thanks a lot! It is working flawless

    Reply
    • @Prasan

      Welcome, am very glad to know this. Thanks for the feedback.

      Reply
  40. Admin@san:~$ sudo kill -9 11555
    sudo: /etc/sudoers: Not a directory

    always telling this command sudo: /etc/sudoers: Not a directory..
    what I should do now?

    Reply
    • @sangeetha

      Ensure that you have the /etc/sudoers file, you might have accidentally deleted it.

      Reply
    • @Gaston

      Welcome, many thanks for the feedback.

      Reply
  41. thanks. worked well

    Reply
    • @Jayaprakash

      Thanks for the feedback, and for following us.

      Reply
    • Welcome, thanks for writing back.

      Reply
  42. Thank you. Worked like a charm

    Reply
    • @Misbah

      Welcome, thanks for the feedback.

      Reply
  43. Thank you so much

    Reply
    • @Hafizh

      Welcome, hope you enjoyed it. Thanks for following us.

      Reply
  44. The fix in the main post seems like a bit of overkill. Only the process actually owning the lock needs to be killed.

    You can find its PID with lsof:

    $ sudo lsof /var/lib/dpkg/lock
    

    Example output:

    lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
    Output information may be incomplete.
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    unattende 3002 root 4uW REG 8,10 0 1471282 /var/lib/dpkg/lock

    In this case, the PID is 3002, and “sudo kill 3002” or “sudo kill -9 3002” should release the lock.

    If lsof lists no process and the problem remains, the lock file may be safely deleted.

    Reply
    • @hendrik

      A handy tip here, many thanks for sharing this with us.

      Reply
  45. Nice and easy to understand explanation.

    Reply
  46. In general, it’s always best to try a simple kill without the -9 option first. This asks the process to exit normally, which allows it to clean up first. Only if the process fails to exit, meaning it’s hung, should you kill -9, which tells to kernel to terminate it.

    Reply
    • @Ron

      That is so true, many thanks for the well explained feedback. This will be so beneficial to many Linux users out there.

      Reply
  47. Another way to remove lock file in the /var/lib/dpkg/ directory is:

    $ sudo fuser -vki /var/lib/dpkg/lock
    
    Reply
    • @Romsat,

      Yeah, thanks for sharing the tip with us, hope it will help our readers like you…

      Reply

Got Something to Say? Join the Discussion... Cancel reply

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Check your email for a magic link to get started.