Try   HackMD

SOLVE: Waiting for cache lock: Could not get lock: /var/lib/dpkg/lock-frontend. (Ubuntu Focal, Rasberry Pi 3 Model B+)

Author: Junner
Date: 5/8/2025

After using sudo apt upgrade, terminal showed:

Waiting for cache lock: Could not get lock: /var/lib/dpkg/lock-frontend. It is held by process 3399.

I checked the process name by

ps -A | grep 3399

The process is unattended-upgr. I knew it's a system service for upgrading packages regularly. I can't turn it off with

sudo systemctl stop unattended-upgrades.service

By doing this, it'll hold there, no terminated.

But we can terminate it by kill. Before doing this, let's carefully looking at who's locking.

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

Someone told me that several processes might there. But for me there was only 3399.

And kill them all:

sudo kill -9 3399

The service will restart immediately. So now we should turn the service off.

sudo systemctl stop unattended-upgrades.service

After rebooting the machine, unattended-upgrades.service will restart. So no worries.

Now we can sudo apt upgrade.