What the message looks like
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 2314 (unattended-upgr)
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?Common causes
unattended-upgradesinstalls security updates in the background, often right after boot.- Another
aptordpkgcommand runs in a second terminal or a script. - A graphical updater (PackageKit, Software Updater) is active.
- A previous run was killed and left a stale lock and an interrupted dpkg state.
Check
- Which process holds the lock?
sudo lsof /var/lib/dpkg/lock-frontend - Package tools that are running
ps aux | grep -E '[a]pt|[d]pkg|[u]nattended' - Is the automatic updater active?
systemctl status unattended-upgrades --no-pager
Fix
- Wait a few minutes. If a process is shown, it is working. Run your command again afterwards.
- If you must continue now, stop the updater cleanly:
sudo systemctl stop unattended-upgrades, once it is idle. - Only if no process holds the lock, repair the state:
sudo dpkg --configure -a, thensudo apt update. - Remove the lock files only as a last resort and only when you are sure nothing uses them:
sudo rm /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock. - In scripts, use
apt-get -o DPkg::Lock::Timeout=120 …so the command waits instead of failing.
FAQ
Is it safe to delete the lock file?
Not while a process uses it. Deleting a lock under a running dpkg can corrupt the package database. Wait, or kill nothing before you know what runs.
Why does it happen right after boot?
The system checks for security updates shortly after start. Give it a few minutes, or wait for unattended-upgrades to finish.