Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

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
3  
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
1  
I would suggest one more thing that you may note when faced with this issue. Do check if your disk drives are mounted. If they are not, you may not be able to acquire the lock as the package installer will not be able to access the filesystem. Hope this helps. :) –  Hari Apr 6 '13 at 12:23
show 1 more comment

15 Answers

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
    
I was updating my software when I got the error message. –  raindrop Aug 16 '13 at 22:04
add comment

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
1  
Great hint in contrast to the half-dozen replies suggesting to just remove the file ;-) I randomly ran in the issue and most likely this is it! –  Alex Jan 21 at 16:14
add comment

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.

share|improve this answer
6  
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
3  
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
add comment

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
add comment

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 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

After that, try opening Synaptic again.

share|improve this answer
    
ok... but why happened this? –  jaime May 26 '12 at 22:40
3  
@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
6  
I would accept this as the best answer. correct one. –  Anwar Shah Apr 6 '13 at 14:37
3  
@AnwarShah no, there are other considerations before going around removing files of the system. –  Braiam Dec 31 '13 at 14:47
1  
rm /var/lib/dpkg/lock; dpkg --configure -a: –  WitchCraft Jan 15 at 15:07
show 1 more comment

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
add comment

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
add comment

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
add comment

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
1  
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 '13 at 14:30
add comment

Do not type the following 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 command:

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
add comment

I see pretty much all the answers recommend deleting the lock. I don't recommend doing that as a first measure; maybe if there is no alternative. The lock is placed when an apt process is running, and is removed when the process completes. If there is a lock with no apparent process running, this may mean the process got stuck for some reason.

If you try

ps aux | grep apt

that will catch processes containing the word apt, at least. If you see an apt-get process or an aptitude process that looks stuck, you can try

kill processnumber

and if that doesn't work try

kill -9 processnumber

This should kill the process and may remove the lock. Killing an apt or aptitude process is harmless unless it is actually in the middle of package installation. In any case, if the process got stuck, you probably don't have a choice but to kill it.

share|improve this answer
1  
Also, I would kill dpkg. This worked for me, as it was trying to finish something it stared before the machine was stopped previously, and couldn't figure it out on his own. –  Link Sep 14 '13 at 18:46
3  
@Link I don't think killing dpkg is a good idea, because usually dpkg is manipulating the package database directly, and this could cause corruption. –  Faheem Mitha Sep 14 '13 at 20:17
add comment

The cause of this error may be Update Manager automatically refreshing the repositories in background (typical right after logging in after a fresh install).

If this is the case just wait few seconds or launch Update Manager to check the status.

share|improve this answer
add comment

I want to share what did help for me, while I am getting E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable) this error.

I'm also getting the same error while installing anything in my system. I did what zurko told. But, my system was not functioning well particularly while building android.

Afterwards I realized that, E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable) this error is because of trying to install another package in another terminal while installation of one package is processing in one terminal.

If we tried to install package one after another, we wont get this kind of error message in future.

Thank you.

share|improve this answer
add comment

It Occurs When you are trying to install another program from terminal [using dpkg or apt] While, there already process of installation of program is running in another terminal[using dpkg or apt] or software center or It Occurs When another program is using DPKG or APT

share|improve this answer
add comment

I am having the same problem; it all started after I tried to install "mailutils" from the Terminal. It didnt worked at all, and I started to receive erros with "postfix" messages. I had to delete postfix, then later mailutils, using the terminal. And reboot my netbook. then, worked again, I can use apt-get from terminal and synaptic again.

share|improve this answer
add comment

protected by Community Apr 20 '13 at 0:30

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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