Created: 2023-09-06 10:23

Ubuntu

Trying to install a package with apt was failed due to it being locked.

$ sudo apt-get install <some-package>
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1753 (packagekitd)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

The following steps solved the problem.

First try to kill any running apt / apt-get process, since I hadn’t started any myself.

sudo killall apt apt-get

The above didn’t work so I went with the dangerous option xD (Note that this can seriously break your system.)

sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*

After that we have to reconfigure the packages.

sudo dpkg --configure -a

Update the repositories.

sudo apt update

And we good to go.

Reference