SnapOverflow

SnapOverflow Logo SnapOverflow Logo

SnapOverflow Navigation

  • Home
  • Server
  • Ubuntu

Mobile menu

Close
  • Home
  • System Administrators
    • Hot Questions
    • New Questions
    • Tags
  • Ubuntu
    • Hot Questions
    • New Questions
    • Tags
  • Help
Home / ubuntu / Questions / 15433
In Process
La Ode Adam Saputra
La Ode Adam Saputra
Asked: 2010-11-30 18:12:48 +0800 CST2010-11-30 18:12:48 +0800 CST 2010-11-30 18:12:48 +0800 CST

Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

  • 772

I get this error when trying to use apt-get:

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 I fix this?

package-management dpkg apt
  • 25 25 Answers
  • 3554400 Views

25 Answers

  • Voted
  1. zurdo
    2012-02-07T18:22:32+08:002012-02-07T18:22:32+08:00

    This should be used as last resort. If you use this carelessly you can end up with a broken system. Please try the other answers first before doing this.

    You can delete the lock file with the following command:

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

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

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

    After that, try opening Synaptic again.

    • 945
  2. Faheem Mitha
    2013-07-04T01:01:58+08:002013-07-04T01:01:58+08:00

    (Note: my original answer was extensively edited by Guillem Jover, the primary dpkg developer.)

    I see pretty much all the answers recommend deleting the lock. That must never be done, it is always preferable to kill dpkg (which is supposed to be resilient against that kind of event), than to even think about removing its lock file (where its presence does not indicate the lock being held). The locks are acquired when a dpkg or an apt process is running, and are released (by the kernel if necessary) when the processes complete or are killed. Newer dpkg and apt versions will print the PID of the process holding the contended lock file, and apt now even waits by default for the locks to be released. This is covered in the dpkg FAQ.

    If you try:

    sudo fuser -vik -TERM /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock
    sudo dpkg --configure --pending
    

    that will prompt to terminate any process currently holding these lock files, which, once killed will get the locks released. If you see an apt-get process or an aptitude process that looks stuck, killing them should be less harmful than when the packaging system is in the middle of a package installation. If the processes are really stuck and you have no other choice, you might need to kill them by passing -KILL instead of -TERM. You then need to finish any pending configuration so that dpkg can get those into a better state, and so that it can also integrate updates to its journal to the main status database.

    Killing a dpkg process directly, if present, is in general not a great idea, because if dpkg is active, some maintainer script might be performing actions that are not resilient against abrupt termination (or crashes), but dpkg internally should be resilient to such abrupt terminations, and it's preferable to do that, than to remove any lock file, which has a way higher chance of damaging both the dpkg database and the filesystem.

    Killing a frontend such as an apt-get or aptitude process, while not ideal, is in general much safer.

    • 745
  3. Bruno Pereira
    2012-01-30T03:27:50+08:002012-01-30T03:27:50+08:00

    Remove your /var/lib/dpkg/lock file and force package reconfiguration.

    sudo rm /var/lib/dpkg/lock
    sudo dpkg --configure -a
    

    It should work after this.

    • 237
  4. poolie
    2010-11-30T19:08:13+08:002010-11-30T19:08:13+08:00

    The most likely way to hit this is:

    • boot Ubuntu
    • start a terminal
    • type sudo apt-get install whatever

    and the command-line apt overlaps with update-manager automatically polling.

    So if you try again in a few minutes that should fix it.

    • 118
  5. Martin Owens -doctormo-
    2010-11-30T18:17:07+08:002010-11-30T18:17:07+08:00

    You will get this message if you forget to use sudo when executing an apt command.

    Otherwise this is a sign that something else is installing or removing software and has locked the apt database while it performs the actions. The programs that can do this are:

    • The Software Center
    • The Update Manager
    • The apt link installer (I think this now goes through SC)
    • The apt-get or aptitude command line utilities.
    • The Synaptic Package Manager

    IMPORTANT: only try the below as a last resort since it can crash your system. First try killing any running instance of apt or aptitude as described in Faheem's answer.

    You can force the lock off by removing the file, but it's not recommended without first closing the program that's holding the lock safely, since you could cause corruption or interrupt an installation (bad). The command provided by João should close the program that holds the lock and then remove the lock but won't protect you from install interruption:

    sudo fuser -cuk /var/lib/dpkg/lock; sudo rm -f /var/lib/dpkg/lock   
    

    And the same command can be used for the apt cache lock:

    sudo fuser -cuk /var/cache/apt/archives/lock; sudo rm -f /var/cache/apt/archives/lock
    
    • 111
  6. karthick87
    2010-11-30T20:55:51+08:002010-11-30T20:55:51+08:00

    Only one program can hold the lock. Make sure that you are not running aptitude, synaptic or adept. Close the program and run it again it should work.You may either have synaptic open, or have another terminal window open running apt-get, or have the update manager running.Check it and see if any of those are running,if any of them is running close it and try again.

    Try this command in terminal to find what is running

    ps -e | grep -e apt -e adept | grep -v grep
    

    Note:
    If that doesn’t print anything, type the following in terminal to remove the lock

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

    Now you can install any Packages.

    • 53
  7. Jairelee
    2017-02-03T02:01:40+08:002017-02-03T02:01:40+08:00

    So far the best way to get it working without breaking a possible background running installation ( as it could happen by removing the lock file), is stopping the service using apt:

    Error:

    # sudo apt-get upgrade
    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?`
    

    Solution:

    sudo systemctl stop apt-daily.timer
    

    After upgrading the system I suggest re-enabling it, as the bug locking it could be fixed with the upgrade.

    sudo systemctl start apt-daily.timer

    I haven't verified this error gets fixed after upgrading. I'll add a new comment once I have that verified

    • 52
  8. Ravexina
    2017-04-24T23:29:06+08:002017-04-24T23:29:06+08:00

    First of all we should check what process created the lock file using lsof:

    sudo lsof /var/lib/dpkg/lock
    

    or in another situation where /var/lib/apt/lists/lock is problematic:

    sudo lsof /var/lib/apt/lists/lock
    

    The output will be close to something like:

    COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
    apt-get   12127 root   4uW  REG  252,1        0    86   /var/lib/apt/lists/lock
    

    Then we should check what the commad is doing, we can find it out using ps, pgrep etc; the command is apt-get so I run:

    pgrep apt-get -a
    

    The -a switch lists the full command for me, in my case it's:

     pgrep -a apt-get
     12127 apt-get update
    

    we can see that it's running update subcommand, I could run something like this too:

    ps -f 12127
    

    which produces:

    UID        PID  PPID  C STIME TTY      STAT   TIME CMD
    root     12127 12126  0 09:39 pts/0    S+     0:00 apt-get update
    

    In this case I would wait for some minute for resource to be freed and if after 2 or 3 minute problem still exist or the command was something that I didn't care about or was not harmful for system (like this apt-get update) I send a SIGTERM to the process:

    sudo kill -15 12127
    

    It should do the work, If it didn't I'm going to send SIGINT this time (It's like pressing CTRL+C):

    sudo kill -2 12127
    

    If it didn't work too, we should send an SIGHUP (kill -1), and finally if nothing works I simply kill the process:

    sudo kill -9 12127
    

    or

    sudo pkill -9 apt-get
    

    Then I remove busy resources:

    sudo rm /var/lib/apt/lists/lock
    
    • 34
  9. Cavaz
    2013-10-05T04:39:50+08:002013-10-05T04:39:50+08:00

    This error may be caused by the Update Manager trying to automatically refresh the list of packages in background, usually right after your login, thus locking the directory.

    In this case just wait few seconds (or more, if your last update was long ago) for it to complete or launch Update Manager to check the status.

    • 23
  10. Wessi
    2015-01-16T01:54:05+08:002015-01-16T01:54:05+08:00

    Don't be so fast to remove something, it may totally damage your system; rather wait until the currently installing or uninstalling program finishes its task and after that you will get access. If you think that there is nothing currently installing or uninstalling, then just reboot your system with the command sudo reboot.

    • 19

Sidebar

Stats

  • Questions 681965
  • Answers 980273
  • Best Answers 280204
  • Users 287326
  • Popular
  • Answers
  • Marko Smith

    How to add a directory to the PATH?

    • 17 Answers
  • Marko Smith

    How do I install .run files?

    • 7 Answers
  • Marko Smith

    How to list all installed packages

    • 24 Answers
  • Marko Smith

    How do I get the CPU temperature?

    • 21 Answers
  • Marko Smith

    Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

    • 25 Answers
  • Marko Smith

    How can I add a user as a new sudoer using the command line?

    • 7 Answers
  • Marko Smith

    Change folder permissions and ownership

    • 9 Answers
  • Marko Smith

    How do you restart Apache?

    • 13 Answers
  • Marko Smith

    How can I uninstall software?

    • 11 Answers
  • Marko Smith

    How can PPAs be removed?

    • 26 Answers
  • Martin Hope
    justingrif How to add a directory to the PATH? 2009-07-23 12:42:23 +0800 CST
  • Martin Hope
    NES How to enable or disable services? 2010-12-30 13:03:32 +0800 CST
  • Martin Hope
    Ivan How to list all installed packages 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra Unable to lock the administration directory (/var/lib/dpkg/) is another process using it? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    Olivier Lalonde How to keep processes running after ending ssh session? 2010-10-22 04:09:13 +0800 CST
  • Martin Hope
    David B How can I add a user as a new sudoer using the command line? 2010-10-16 04:02:45 +0800 CST
  • Martin Hope
    Hans How do I remove old kernel versions to clean up the boot menu? 2010-08-21 19:37:01 +0800 CST
  • Martin Hope
    David Barry How do I determine the total size of a directory (folder) from the command line? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "The following packages have been kept back:" Why and how do I solve it? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford How can PPAs be removed? 2010-07-30 01:09:42 +0800 CST

Related Questions

Trending Tags

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • Home
  • Questions
    • Hot Questions
    • New Questions
  • Tags
  • Help

Footer

SnapOverflow

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Help

© 2022 SOF-TR. All Rights Reserve