Sometimes while using apt-get command to install some packages, we come across an error like:
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?
For ex: I was trying to install mysql-server on my machine using apt-get
taran@taran:~$ sudo apt-get install mysql-server
and it showed an error like
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?
This could be a result of ubuntu running some apt-get process in background which is holding the lock, and is not allowing you to install anything using apt-get.
If this is the reason, then you can search for the process manually and kill it using its process id.
Ex:
ps -A | grep apt-get
This will list all the process running as apt-get
If there is some process listed then we can kill that process using kill command like
sudo kill -9 <process_id>
for example if process id is 5689
sudo kill -9 5689
and then run the command
sudo apt-get update
if there are no process listed using grep command, then we have to remove the lock forcefully.
There are various options for the same, you can use lsof command, which will list the open files, i.e it is used to find out which files are open by which process. And then we can kill the process manually . Ex:
In the following command we are finding the process that owns the lock file
taran@taran:~$ sudo lsof /var/lib/dpkg/lock
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
aptd 3192 root 74uW REG 8,3 0 1704592 /var/lib/dpkg/lock
taran@taran:~$ sudo kill -9 3192
If the above steps does not solve your problem, remove the lock file and force package reconfiguration.
To delete the lock file we will use the following command:
sudo rm /var/lib/apt/lists/lock
We also need to delete the cached lock file:
sudo rm /var/cache/apt/archives/lock
And at last we force the package reconfiguration:
sudo dpkg --configure -a
1 Comment(s)