Linux APT 'Could Not Get Lock' — dpkg Lock Error
Errorpackage manager
Overview
APT 'Could not get lock /var/lib/dpkg/lock' error means another package manager process is running or a previous one crashed without releasing the lock.
Key Details
- APT uses file locks to prevent concurrent package operations
- Lock files: /var/lib/dpkg/lock, /var/lib/apt/lists/lock, /var/cache/apt/archives/lock
- Only one package manager process can run at a time
- Unattended-upgrades running in the background is a common cause
- Force-removing locks can corrupt the package database
Common Causes
- Another apt, dpkg, or Software Center process is running
- Unattended-upgrades service running automatic updates in background
- Previous apt process crashed without releasing the lock file
- System booting and running initial package operations
- Snap or Flatpak triggering apt operations
Steps
- 1Wait 2-3 minutes — unattended-upgrades may be running
- 2Check for running processes: ps aux | grep -i apt
- 3If no process is running, remove stale locks: sudo rm /var/lib/dpkg/lock-frontend && sudo rm /var/lib/dpkg/lock
- 4Reconfigure packages: sudo dpkg --configure -a
- 5Then retry: sudo apt update && sudo apt install package-name
Tags
linuxaptdpkglockubuntu
More in Package Manager
Frequently Asked Questions
Only if no apt/dpkg process is actually running. Check with ps aux | grep apt first. Deleting locks while a process runs can corrupt your system.