While updating or installing packages using apt, apt-get, aptitude, or dpkg, you might get an error saying ‘unable to acquire the dpkg frontend lock‘ or a similar error related to locks. The error message looks something like this:
You might also get these error messages:
E: Could not get lock /var/lib/apt/lists/lock – open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/
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?
It might also look like this while using the Software Center/App Store :
In this article, we cover how to resolve this error so that you can continue with your important work on your Ubuntu/Debian machine.
Why does the “unable to acquire the dpkg frontend lock” error show up?
Whenever a program like apt tries to update or install package(s), it first locks a particular file. Any other program that tries to update or install packages has to check whether this file’s lock is available or not. Only 1 program can own a lock at a given time.
It might happen that another program was updating/installing a package and then you try to
sudo apt install something while the other program still owns the lock. Since
apt can’t own the lock now, it will give an error saying ‘unable to acquire the dpkg frontend lock‘ or something similar.
This ‘locking mechanism‘ exists because package updates can’t be run in parallel, they could interfere with each other. Now that we understand why this error is thrown, we can move on to fixing it.
How to Fix “unable to acquire the dpkg frontend lock”
Now that we understand the reason behind the error, let’s try to fix it.
This plan is named Plan 0 because it’s quite trivial and easy to overlook for a beginner. While installing a package using the apt command, you must have superuser privileges.
If you forgot to prepend your
apt install with
sudo, apt will yell at you saying it couldn’t open the lock file. This isn’t exactly the ‘unable to acquire the dpkg frontend lock’ error, but it is an error that can frustrate someone who has just started the Linux journey.
This plan involves finding out the process that is running updates already and either waiting for it or gracefully killing it. You can find the running processes using the ps command.
ps aux | grep -i apt
As you can see an update is already in progress. If the process that is the last column of output of
ps command is
apt.systemd.daily, you should probably wait for a few minutes as this is the
apt-daily.service service that runs each time the system is booted. The waiting time depends on the system.
If the last column of
ps command is like the one shown in the screenshot above, you can kill it using the
kill command. The PID(Process ID) can be obtained from the 2nd column of the ps command output.
sudo kill <process_id>
When apt is killed, it also releases the lock held by it.
If Plan 1 didn’t work for you, it might have happened because of the lock on the files. If the program owning the lock was abruptly terminated it might not have released the lock. Use the
lsof command to see which process owns the lock on these files:
sudo lsof /var/lib/dpkg/lock sudo lsof /var/lib/apt/lists/lock sudo lsof /var/cache/apt/archives/lock
Some of the above commands might not give an output but for me
lsof /var/lib/dpkg/lock gave the following output.
Then use the
PID of the command to kill the command.
sudo kill -9 <process_id>
-9 sends a
SIGKILL signal to the program passed as kill command’s argument.
Then you can manually delete the lock files using the
sudo rm /var/lib/apt/lists/lock sudo rm /var/cache/apt/archives/lock sudo rm /var/lib/dpkg/lock
Note: Manually removing lock files is not recommended. As a result Plan 2 should be used as a last resort
After deleting the locks reconfigure dpkg.
sudo dpkg --configure -a
Did it work for you?
Were you able to solve this unable to acquire the dpkg frontend lock error after reading this article? If yes, which plan worked for you? Let us know in the comments.