How to Fix “E: Unable to Obtain Lock / var / lib / dpkg / lock” Error on Ubuntu

In this article we will learn How to fix “dpkg: error: dpkg front-end lock is locked by another process”. Whenever we install software, “dpkg: error: dpkg front-end lock is locked by another process“. dpkg Is an Package manager Debian based system. it can installation, Removewith set up package, But unlike other package management systems, it cannot automatically download and install packages or their dependencies. of dpkg It is a low-level tool in itself. APT (Advanced packaging tools) (An advanced tool) is more commonly used than dpkg because it can bring packages to remote locations and handle complex package relationships, such as dependency repair. Frontends such as Aptitude (NCRS) and Synaptic (GTK +) are used for APT’s friendly interface.

Fix “E: Unable to obtain lock / var / lib / dpkg / lock” error on Ubuntu

If you encounter this issue, wait a few minutes until the current installation or update or uninstall task is complete. Depending on the size of the update, this process will take some time (5 to 10 minutes or more) to complete. After the task is completed, the lock will be released automatically. However, if the process is stuck for some reason and the apt database is locked for a few minutes, then you have no choice but to remove the lock. In this case, follow the steps below to fix it. First, let’s find out which process owns the locked file, i.e. / var / lib / dpkg / lock.

$ sudo lsof /var/lib/dpkg/lock

For example, if the lock files are different /var/lib/dpkg/lock-frontendYou can find PID of the process Own this lock file with:

$ 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 owns the locked file

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

$ sudo kill -9 9718

You can now safely remove the lock using the following command:

$ sudo rm /var/lib/dpkg/lock


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


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

In addition, you may need to delete locked files in the cache directory:

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

After unlocking, run:

$ sudo dpkg --configure -a

This should resolve the issue.

Is it useful for you?

I hope this little trick can help you resolve the “Unable to acquire lock / var / lib / dpkg / lock” error. If you are still facing issues, please let me know. I will try to help you. Any other suggestions are welcome in the comments.