I get this error when trying to use
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?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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 sudo rm /var/lib/dpkg/lock
After that, try opening Synaptic again.
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 [a]pt
pgrep -a 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
sudo kill processnumber
and if that doesn't work try
sudo kill -9 processnumber
This should kill the process and may remove the lock. Killing an
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.
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.
aptitude process is in general much safer.
/var/lib/dpkg/lock file and force package reconfiguration.
sudo rm /var/lib/dpkg/lock sudo dpkg --configure -a
It should work after this.
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:
IMPORTANT: only try the below as a last resort since it can crash your system. First try killing any running instance of
aptitude as described in Faheem's answer.
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
The most likely way to hit this is:
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.
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.
So far the best way to get it working without breaking a possible background running installation ( as it could happen by removing the lock file), is stopping the service using apt:
# sudo apt-get upgrade 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?`
sudo systemctl stop apt-daily.timer
After upgrading the system I suggest re-enabling it, as the bug locking it could be fixed with the upgrade.
sudo systemctl start apt-daily.timer
I haven't verified this error gets fixed after upgrading. I'll add a new comment once I have that verified
First of all we should check what process created the lock file using
sudo lsof /var/lib/dpkg/lock
or in another situation where
/var/lib/apt/lists/lock is problematic:
sudo lsof /var/lib/apt/lists/lock
The output will be close to something like:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME apt-get 12127 root 4uW REG 252,1 0 86 /var/lib/apt/lists/lock
Then we should check what the commad is doing, we can find it out using
pgrep etc; the command is
apt-get so I run:
pgrep apt-get -a
-a switch lists the full command for me, in my case it's:
pgrep -a apt-get 12127 apt-get update
we can see that it's running
update subcommand, I could run something like this too:
ps -f 12127
UID PID PPID C STIME TTY STAT TIME CMD root 12127 12126 0 09:39 pts/0 S+ 0:00 apt-get update
In this case I would wait for some minute for resource to be freed and if after 2 or 3 minute problem still exist or the command was something that I didn't care about or was not harmful for system (like this
apt-get update) I send a
SIGTERM to the process:
sudo kill -15 12127
It should do the work, If it didn't I'm going to send
SIGINT this time (It's like pressing CTRL+C):
sudo kill -2 12127
If it didn't work too, we should send an
kill -1), and finally if nothing works I simply kill the process:
sudo kill -9 12127
sudo pkill -9 apt-get
Then I remove busy resources:
sudo rm /var/lib/apt/lists/lock
This error may be caused by the Update Manager trying to automatically refresh the list of packages in background, usually right after your login, thus locking the directory.
In this case just wait few seconds (or more, if your last update was long ago) for it to complete or launch Update Manager to check the status.
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: https://askubuntu.com/a/15469/68707
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
If you have security updates set to auto-install this will happen frequently. I literally wait 30 seconds and it fixes the issue. Just throwing this out there in case anyone else encounters this issue.
In my case, I had to wait for several minutes for the lock to be released (looks like
apt used to hold it). This all happened right after system boot.
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
I have had this issue numerous times. For me, it was almost always caused by apt-get or some GUI that called it getting hung for some reason. I had to kill it which left various locks in place.
The other answers bring up very good points about making sure no updates are currently running before doing anything drastic like removing lock files. However, once you are sure that's not the case, the following usually works for me. I got it by reading many answers to questions like this one.
While most or all of this is presented in the other answers, this distills the fix down to a few commands.
sudo fuser -vki /var/lib/dpkg/lock sudo fuser -vki /var/cache/apt/archives/lock sudo fuser -vki /var/cache/debconf/config.dat sudo dpkg --configure -a
Use for unlocking the package system after an update of some kind crashed or terminated without finishing in some other way. These commands should be run in the order presented.
I don't see this answer anywhere above but on Ubuntu 16.04, I encountered this problem as well. The cause was the time on my computer was set into the future. (This is because I'm on a Windows+Ubuntu dual boot system and I guess I have messed up local time vs UTC time.)
One odd thing was that the locked file's date and time was the exact date and time that I ran the program.
I then used "fuser" as described in earlier posts and apt worked, but I was getting complaints about needing to run
dpkg -a -reconfigure. When I did that, I got errors like:
newline in field name #padding
in files like '/var/lib/dpkg/updates/0003'.
All of this was very strange as I've never seen it before. So, I thought these were symptoms and changed my data and time manually. I knew there was a problem with the date/time when I logged in, but was ignoring it. (Previously, it was setting it automatically via the Internet and NTP).
Then, all of the above problems were fixed... Hopefully, this helps someone else! The most notable symptom is perhaps the date/time of the lock file being the exact date/time that you are trying to run the command.
In my case, X crashed while
apt-get was still removing old kernels. I used the System Monitor to confirm it was still running and not stuck. Everything was fine once the process finished.
Check the Launcher to see if
Software Updater is running. If so maximize it and have a look at what it is doing. If it is still checking, then wait for it to complete. When it completes it might tell you the software is up-to-date so close the app. If it says there are updates available, either do the update or click "remind me later". After this this app closes you can go back to using
Software Updater is not running, just use the Dash to invoke it and the wait for completion and then decide if you want to update or click "remind me later". After this this app closes you can go back to using
In my case I was getting the same message by not realizing I had switched to root user and was trying sudo apt-get. Once I realized this I just ran apt-get, and it worked. Silly, but it might still explain the error for some.
sudo killall -9 apt && sudo killall -9 dpkg
Use at your own risk
in my case, after:
then I get that problems
sudo apt update sudp apt upgrade
I fixed that, running the command that was showed me after run
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?
sudo apt update
apt list --upgradable
This command will show you a list of programs in my case only Firefox, I closed Firefox, then could ran the command again without problems.
sudo apt upgrade
For people who are interested in proactively preventing this bug in their scripts, I found that the -q flag on
apt upgrade -yq was causing this issue for me. During the upgrade process I guess it would occasionally give me warnings (something along the lines of updating the desktop, would I like to continue), and if these warnings were suppressed, then I guess that causes apt to not unlock the files it was protecting and it got stuck.
Admittedly, I had trouble reproducing this error 100% of the time, but eliminating that -q option completely fixed the issue for me.
Like most everyone else I waited for the lock to be removed. After 30 minutes I gave up and hard booted to a different distribution. From there I used the internet for some research which landed me here.
It turns out
unattended-upgrades.service is running. I found that be rebooting into the broken system and running:
sudo systemctl disable apt-daily.service sudo systemctl disable unattended-upgrades.service sudo systemctl disable apt-daily-upgrade.service sudo systemctl disable apt-daily-upgrade.timer sudo systemctl disable apt-daily.timer sudo shutdown -r # Note it will take a couple minutes to reboot
allowed me to get the broken system working again for:
sudo apt update sudo apt upgrade sudo apt install -f
However it didn't fix the kept-back packages and impossible situation reported by
apt in the first place. It would appear this was causing
apt to lock up at boot in the first place.
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 (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?