Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.
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?

share|improve this question
1  
This is also true if you reboot? Maybe some old apt thread is locking the file, you need to find out which and kill it or just rebooting will do it. – Bruno Pereira Jan 29 '12 at 11:19
yes, even after reboots im getting the same responses. Do you know how can I find which apt thread is locking the file?. Thank you! – kern Jan 29 '12 at 11:25
1  
Did you try this answer? askubuntu.com/a/15469/25798 – jokerdino Jan 29 '12 at 11:27
2  
This procedure almost always fixes this problem, and when it doesn't, its output (the text from the Terminal) is sometimes useful. If you decide to do it, you can add this text to your question. – Eliah Kagan Jun 6 '12 at 9:10
@EliahKagan link fixed my problem – ajma Jul 24 '12 at 20:44
show 1 more comment

11 Answers

up vote 38 down vote accepted

WARNING: This answer is applicable to Ubuntu version < 11.04, do not use it in a newer version as it will hard freeze your system

As per the other answers there is a package management app holding the lock. When unsure do not manually remove the lock, first run:

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

This will kill any processes opening the file before removing it.

share|improve this answer
8  
Khe khem.. How this helps? I got this var lock and found this page and did this command and it made black screen and no way opening anything. Not alt+ctrl+f(1-8) – Kangarooo Jan 12 at 23:22
3  
Agreed with @Kangarooo. – Sam Hoice Jan 24 at 17:16
6  
My screen went black when I ran this command. – igneosaur Jan 30 at 14:00
2  
This command did not work for me. It killed my session, and prevent me from switching ttys as per @Kangarooo. – Sparhawk Feb 15 at 0:26
2  
How can this be the accepted answer? Not only I also got the black screen of death, but I had to hard reboot, which left my hard disk corrupt. I wish I could downvote a million times. – Xananax Mar 28 at 3:18
show 6 more comments

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.

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

share|improve this answer

You can delete the lock file with

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

after that try open synaptic again

share|improve this answer
Thanks! That worked. – David Faux Mar 29 '12 at 0:43
ok... but why happened this? – jaime May 26 '12 at 22:40
@jaime: probably apt-get (or some GUI frontend to it) was halted while executing, leaving apt in a locked state. – bouke Sep 13 '12 at 12:15
1  
I would accept this as the best answer. correct one. – Anwar Apr 6 at 14:37

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.

share|improve this answer
these commands helped, but now when I tried to install again, got this reply : Could not get lock /var/cache/apt/archives/lock - open. I think I would have to do like previous unlocking problem, but please tell me the exact keywords for command. I'm an absolute beginner. – kern Jan 29 '12 at 11:38
sudo - execute command as root, rm - remove file. Maybe try sudo rm /var/cache/apt/archives/lock – kubahaha Sep 24 '12 at 13:56

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 make effect, type the following in terminal that will remove the lock
sudo rm /var/lib/dpkg/lock
sudo rm /var/cache/apt/archives/lock
Now you can install any Packages.

share|improve this answer
2  
Deleting the lock file is, what I would consider, a dangerous thing to do. If another process is locking for a valid reason - and you remove that lock file and force an install with what you were doing prior - you could seriously, in a negative way, affect your system. – Marco Ceppi Nov 30 '10 at 5:49
2  
That's why i have given that in Note.If all the above fails the only way is to remove the lock.It wont cause any problem as long as dpkg and apt-get/aptitude processes aren't running – karthick87 Nov 30 '10 at 5:55

Just sudo rm -f /var/lib/apt/lists/lock and try again.

apt-fast MAY be responsible for not unlocking properly; this happens sometimes when you abort apt-get or dpkg too.

share|improve this answer

My guess is that 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.

share|improve this answer

This will happen if you have 'Update Manager' running in parallel for any update check or install as install process places Lock. If you're facing the same error without 'Update Manager' running you have to remove it from /var/lib/dgkg/lock, which definitely you can't do it manually

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

works fine. Taken from: http://askubuntu.com/a/15469/68707

share|improve this answer

Do not type the command!!!!

sudo fuser -cuk /var/lib/dpkg/lock

The process "fuser" will access the communication with the graphics card, and possibly eliminate it. If you plan to execute this command first type (ctrl+alt+F2) and execute it in a different tty session, so your graphics is not changed while it is used by your Xorg session.

I would try the classic

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

or just...

sudo rm /var/lib/dpkg/lock

If I was to do this while staying in Xorg(or the GUI)

share|improve this answer

After running commands told by Kern in his answer, you may try this:

sudo rm -r /var/cache/apt/archives/{lock,partial} 

Now run:

sudo apt-get update && sudo apt-get upgrade 
share|improve this answer

If you have an aborted upgrade you get a lock too, for removing that lock execute following commands

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

I sometimes minimize my synaptic and forget it's open and get the error when working in terminal just close all programs synaptic. upgrade manager, and software center

share|improve this answer
I'm afraid I prefer @João Pinto's solution. Deleting a lock file without checking whether any processes are using is a bad idea, so I'm downvoting this. – Flimm Dec 4 '12 at 14:03
This is indeed a very bad idea. These lockfiles should never be deleted. apt/dpkg don't leave them locked when the process exits, so if something says they are locked, they damn well are. – Dennis Kaarsemaker Apr 6 at 14:30

protected by Community Apr 20 at 0:30

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.