How to fix apt lock-frontend error in Ubuntu
linux
ubuntu
dpkg
lock-frontend
lock
Today I was trying to upgrade my ubuntu server by running the command apt upgrade
when I encountered the following error:
root@admfactory:~# apt upgrade
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
root@admfactory:~#
This error could have many reasons, but in my case, it was because I accidentally close the terminal session, and it was in the middle of an application installation.
This method works in most of the cases as it is the most obvious reason: there is another process that uses the apt application.
Step1 - Get the Process ID
Run the following command line to get the ID of the process that is running the apt
or apt-get
command.
ps aux | grep -i apt
The command shows that there is a process with ID 20485 that is using the apt
application. You can ignore the last line containing grep –color=auto
. This process is from the current command to highlight the keyword searched, in our case apt.
Step2 - Kill the process
Run the following command line to kill the process that is runningapt
or apt-get
command:
sudo kill -9 20485
Where 20485 is the process ID of the application that need to be killed.
Easiest way would be to use killall
command. This will kill all the instances if the running application:
sudo killall apt apt-get
Step3 - Reconfigure the dpkp command
After a forced stop of the apt command, a reconfigure of the packages is required.
To do this run the following command line:
sudo dpkg --configure -a
For me this took about 3 min.
During the process, I was asked to confirm the restart of the affected services.
Hope this solved the lock lock-frontend
problem.