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.
Related videos on Youtube
Author by
diracdeltafunk
I love it when things just work. Algebra junkie. https://youtube.com/c/BenSpitz
Updated on September 18, 2022Comments
-
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 almost 12 yearsHave 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 almost 12 years@Ben7005 I'd hold off on the rebooting and wait for your downloads to finish
-
Admin over 10 years3 years ago there was also this answer on askubuntu.
-
-
diracdeltafunk almost 12 yearsI am downloading some software from the software center... I'll finish that and see if it works.
-
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 almost 12 yearsThat'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 almost 12 yearsEither 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 runningaptitude
remotely and losing connection whiledpkg
was waiting for user input (eg, to tell it what to do with a modified config file) -
Arcadien almost 12 yearscheck if the lockfile exists, and if there is no dpkg/apt process running, delete it.
-
Levon almost 12 years@Ben7005 So, what happened? Did you resolve the problem? Just curious :)
-
diracdeltafunk almost 12 yearsYes, you had the right solution. I was just being stupid.
-
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 over 10 yearsIt 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 runningapt
processes and kill them. -
JackDaniels over 10 yearsYup @terdon I mentioned in first line that it should be done when no other solutions helps.