In this article we are going to learn How to fix “dpkg: error: dpkg frontend lock is locked by another process”.
Whenever we are installing software, an error occurs with “dpkg: error: dpkg frontend lock is locked by another process“. dpkg is a package manager for Debian-based systems. It can install, remove, and build packages, but unlike other package management systems, it cannot automatically download and install packages or their dependencies. The dpkg itself is a low level tool. APT (Advanced Package Tool), a high-level tool, is more commonly used than dpkg because it can bring packages to remote locations and deal with complex package relationships such as dependency fixes. Frontends like Aptitude (NCRS) and Synaptic (GTK +) are used for their friendly interface for APT.

Fix “E: Could not get lock /var/lib/dpkg/lock” Error On Ubuntu

If you ever encountered with this problem, wait for a few minutes until the currently installing or updating or uninstalling task to complete. This process will take some time (5 to 10 minutes or more) to complete depending upon the size of the update. Once that task is completed, the lock will be released automatically.
But if the process is stuck for some reason and it locked the apt database for several minutes, you have no choice but remove the lock. In that case, follow the below procedure to fix it.
First, let us find out which process that owns the lock file i.e /var/lib/dpkg/lock.

$ sudo lsof /var/lib/dpkg/lock

If the lock file is different, for example /var/lib/dpkg/lock-frontend, you can find PID of the process that owns this lock file with command:

$ sudo lsof /var/lib/dpkg/lock-frontend

If the lock file is /var/lib/apt/lists/lock, run:

$ sudo lsof /var/lib/apt/lists/lock


Example output:

find out which process that owns the lock file

find out which process that owns the lock file

As you can see in the above output, the PID of the process that holds the lock file is 9718.
Just kill it to release the lock using command:

$ sudo kill -9 9718

You can now safely remove the lock with commands:

$ sudo rm /var/lib/dpkg/lock

Or,

$ sudo rm /var/lib/dpkg/lock-frontend

Or,

$ sudo rm /var/lib/apt/lists/lock

Also you may need to delete the lock file in the cache directory:

$ sudo rm /var/cache/apt/archives/lock

After removing the lock, run:

$ sudo dpkg --configure -a

This should fix the problem.

Did it work for you?

I hope this small tip helped you fix the “Could not get lock /var/lib/dpkg/lock” error. If you are still facing issue, let me know. I’ll try to help you out.
Any other suggestions are also welcome in the comments.