Many times you might have encountered the error like “E: Could not get lock /var/lib/dpkg/lock”. It means that unable to lock the administration directory as another process is using it. This error can be annoying especially for new users who are trying Linux operating system the first time. If you don’t know the cause of the error then it gets difficult to solve that one.
Below is an example showing the lock file error on Ubuntu 16.04 LTS.
How to solve “E: Could not get lock /var/lib/dpkg/lock” error?
There are several ways to fix that error. But, we will go through only effective ways to fix that error. We will go through the following steps to fix that error.
STEP 1: Kill all the running apt processes
Using terminal command we have to kill all the apt process which are running in the background. First we need to generate a list of all apt processes. This can be generated by typing following command in the Terminal Emulator.
$ ps -A | grep apt
Above command will show you all the apt process running in the background. It gives you output like “7430 pts/7 00:00:00 apt-get”. Here, 7430 is Process ID. For your case number can be different.
STEP 2: Kill the background apt processes
Now we just need to kill the apt processes running in the background of the system. To kill that process we need to type following command in the Terminal Emulator.
sudo kill -SIGKILL <process ID> Example: sudo kill -SIGKILL 7430
It will kill the ongoing process running in the background. Still, facing the same issue then try following method to fix “E: Could not get lock /var/lib/dpkg/lock” issue.
If above method is not working for you then running process in the background can be of different type. For such process, we need to remove the lock from /var/lib/dpkg/lock directory. After removing the lock, we can continue installing software and resources.
How to remove the lock on /var/lib/dpkg/lock directory?
Open the terminal and enter the following command to remove the lock on the directory.
It will ask you for the confirmation after entering above command.
rm: remove write-protected regular empty file ‘/var/lib/dpkg/lock’?
To remove the lock press Y after seeing this message. If the lock doesn’t remove then try 2-3 times. After unlocking the directory you can continue your work.
Easy and simple way to fix “E: Could not get lock /var/lib/dpkg/lock” issue on any Linux based operating system. For much more tips stay tuned.