I cannot install new packages: "Could not get lock /var/lib/dpkg/lock"

12,497

Solution 1

Do you have the GUI package manager/or update manager programs running? If so there's a conflict, simply close those programs down and your command line should work.

Solution 2

This should be used as last resource. If you use this carelessly you can end with a broken system. Please evaluate other answers first before trying this. You can delete the lock file with the following command:

sudo rm /var/lib/dpkg/lock

After that, try installing again.

Share:
12,497

Related videos on Youtube

diracdeltafunk
Author by

diracdeltafunk

I love it when things just work. Algebra junkie. https://youtube.com/c/BenSpitz

Updated on September 18, 2022

Comments

  • diracdeltafunk
    diracdeltafunk over 1 year

    I tried to install jdk/jre:

    ben@ubuntu:~$ sudo apt-get install openjdk-7-jre-headless
    

    However, I got this message:

    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?
    

    I cannot get git to install either, so I don't think it is a problem with the specific package I selected. What that error means, and how to deal with it?

    • David Bernard
      David Bernard almost 12 years
      Have you tried just rebooting? An error like that usually indicates that another package manager has locked the whole system. If you reboot, it should not persist.
    • Levon
      Levon almost 12 years
      @Ben7005 I'd hold off on the rebooting and wait for your downloads to finish
    • Admin
      Admin over 10 years
      3 years ago there was also this answer on askubuntu.
  • diracdeltafunk
    diracdeltafunk almost 12 years
    I am downloading some software from the software center... I'll finish that and see if it works.
  • Levon
    Levon almost 12 years
    @Ben7005 That's most likely it .. in fact trying to use both of those GUI programs at the same time will result in the same error message, so I'd not be surprised you'd get this with the command line while something else is going on.
  • Simon Gates
    Simon Gates almost 12 years
    That's definitely it. Only one of aptitude, apt-get, dpkg and the software centre can install at the same time. They use a lock on /var/lib/dpkg/lock to ensure that, hence the error message.
  • Shadur
    Shadur almost 12 years
    Either that or one of the above frontends was /very/ rudely interrupted mid-install and its dpkg backend was still hanging on to the lock. Can sometimes happen running aptitude remotely and losing connection while dpkg was waiting for user input (eg, to tell it what to do with a modified config file)
  • Arcadien
    Arcadien almost 12 years
    check if the lockfile exists, and if there is no dpkg/apt process running, delete it.
  • Levon
    Levon almost 12 years
    @Ben7005 So, what happened? Did you resolve the problem? Just curious :)
  • diracdeltafunk
    diracdeltafunk almost 12 years
    Yes, you had the right solution. I was just being stupid.
  • Levon
    Levon almost 12 years
    @Ben7005 Glad it worked out. FWIW, I don't think you were being stupid, you just came up against a limitation of the system.
  • terdon
    terdon over 10 years
    It works on all distributions that use apt, not all Linuxes. It is also a pretty bad idea, as you point out, the OP should first look for running apt processes and kill them.
  • JackDaniels
    JackDaniels over 10 years
    Yup @terdon I mentioned in first line that it should be done when no other solutions helps.