This error occurs when another apt process is actively accessing the package cache, or a previous operation left a stale lock file. The lock prevents multiple package operations from corrupting the cache simultaneously. Waiting for background processes or removing stale locks will resolve this issue.
The apt package manager uses lock files to prevent concurrent access to critical package cache directories. The lock at /var/cache/apt/archives/lock protects the package archive cache from being read or written by multiple processes simultaneously. When apt cannot obtain this lock (error code 11 means "Resource temporarily unavailable"), it indicates either another apt process is actively running, unattended system updates are in progress, or a previous operation was interrupted and left a stale lock file behind. Unlike the dpkg lock which protects the entire package database, this specific lock protects just the downloaded package archives cache.
Before trying anything else, wait 1-2 minutes for any running apt or unattended-upgrade processes to finish:
sudo lsof /var/cache/apt/archives/lockThis command shows which processes currently hold the lock. Common ones are:
- apt, apt-get: Another apt operation is running
- unattended-upgr: Automatic security updates are in progress
- apt-daily-upgrade: Scheduled system updates
If you see output with these processes, simply wait. The lock will be released automatically once they complete.
On Ubuntu and Debian systems, unattended-upgrades runs automatically (usually daily). Check its status:
sudo systemctl status apt-daily-upgrade.serviceIf it shows "active (running)", your system is performing security updates. Wait 5-30 minutes depending on how many packages need updating:
sudo systemctl status apt-daily.serviceDo NOT interrupt or kill these processes—they perform critical security updates. Once they finish, the lock will be released and apt will work normally.
If background processes appear stuck and haven't released the lock after waiting, use fuser to safely terminate them:
sudo fuser -vik -TERM /var/cache/apt/archives/lockThis command:
- -v: Verbose, shows which processes are killed
- -i: Interactive (asks before killing, add -k to skip confirmation)
- -TERM: Uses graceful termination first
If this doesn't work, try with -KILL:
sudo fuser -vik -KILL /var/cache/apt/archives/lockAfter terminating processes, you may need to repair dpkg:
sudo dpkg --configure -aIf the lock persists after waiting and terminating processes, remove the stale lock file:
sudo rm /var/cache/apt/archives/lockThen also remove related locks to ensure a clean state:
sudo rm -f /var/lib/apt/lists/lock
sudo rm -f /var/lib/dpkg/lock
sudo rm -f /var/lib/dpkg/lock-frontendReconfigure dpkg to ensure it's in a good state:
sudo dpkg --configure -aNow try your apt command again:
sudo apt updateIf removing lock files causes apt to complain about cache corruption, clean and rebuild the cache:
sudo apt clean
sudo apt autocleanThen update the package list:
sudo apt updateIf apt still complains, force a full cache refresh:
sudo apt update --fix-missingIf you've tried all the above steps and still cannot use apt, a reboot will clear all locks and reset apt state:
sudo rebootAfter rebooting, apt should work normally. The lock files will be recreated as needed.
The lock file at /var/cache/apt/archives/lock is separate from /var/lib/dpkg/lock and /var/lib/apt/lists/lock. Each protects different parts of the package management system: /var/cache/apt/archives/lock guards the downloaded .deb package files, /var/lib/apt/lists/lock protects the package index files (what apt knows is available), and /var/lib/dpkg/lock protects the actual package database. In Docker, this error is common when apt operations run during image builds while the package cache hasn't been cleared. The fix is to use apt-get clean before new RUN commands. On systems with unattended-upgrades, you can check scheduled times with grep "APT::Periodic" /etc/apt/apt.conf.d/*. Some users disable unattended-upgrades if it conflicts with their schedule by creating /etc/apt/apt.conf.d/99disable-unattended-upgrades with content APT::Periodic::Unattended-Upgrade "0";. However, this trades automatic security updates for manual control—ensure you remember to apply security updates manually.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT