Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
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
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
You can use sudo lsof /var/lib/dpkg/lock to find the process that owns the lock file (if empty, assume the lock is left over from a previous boot and can be sudo rmd), then consider doing a sudo kill -9 <PID> (get <PID> from lsof output. – waltinator Mar 17 '14 at 22:01
This can be a sign that something else is installing or removing software and has locked the apt database while it performs the actions. – Foreever Feb 3 '15 at 4:32

13 Answers 13

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 Hablutzel 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
I would accept this as the best answer. correct one. – Anwar Shah Apr 6 '13 at 14:37
@AnwarShah no, there are other considerations before going around removing files of the system. – Braiam Dec 31 '13 at 14:47
rm /var/lib/dpkg/lock; dpkg --configure -a: – WitchCraft Jan 15 '14 at 15:07

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.

Killing a dpkg process directly, if present, is not a good idea, because if dpkg is active, it is probably manipulating the package database, and killing it may leave the package database in an inconsistent state; i.e. corrupted.

Killing an apt-get or aptitude process is in general much safer.

share|improve this answer
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. – morynicz Sep 14 '13 at 18:46
@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
There was no need to kill dpkg. After killing the stuck apt-get process, dpkg went away automatically. – friederbluemle Oct 3 '14 at 4:16
If killing dpkg can corrupt its database, dpkg was badly designed. Period. – Jay Sullivan Nov 18 '14 at 3:36
This one worked for me thanks – Kuruyiva Mar 15 '15 at 14:09

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
This crashed for me- – umpirsky Sep 21 '14 at 17:33
sudo fuser -cuk /var/cache/apt/archives/lock directly rebooted my computer. apt-get is now unlocked. – Maxime R. Dec 4 '14 at 21:47
This crashed my entire server. – 에이바 Jan 5 '15 at 21:28
Killing apt or dpkg half way through is not a great idea. – poolie Feb 2 '15 at 18:12

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
This is not a good suggestion: blindly removing the luck may corrupt dpkg's state. – poolie Feb 2 '15 at 18:09
Yes! This! Works! – petur Feb 2 at 10:51

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

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

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
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 '14 at 16:14
Safe enough, had to wait a little before sudo apt-get install could work. – sargas May 11 '15 at 17:56

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:

share|improve this answer
This was the problem in my case! – LondonRob Sep 19 '14 at 13:12
Better solution since fuser command used to track down other process (if still alive) – Lars Nordin Mar 18 '15 at 11:50

Reboot/logout will do it as well if you do not want to wait.

share|improve this answer

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

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.

share|improve this answer

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

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

protected by Community Apr 20 '13 at 0:30

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, 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.