This error occurs when the APT package manager cannot acquire an exclusive lock on the dpkg database, usually because another package management process is running. The lock file prevents simultaneous package operations that could corrupt the system.
When you run an apt command (apt install, apt update, apt upgrade, etc.), the system creates a lock file at /var/lib/dpkg/lock to prevent other processes from modifying the package database simultaneously. If another process holds the lock when you issue a command, apt cannot proceed and displays this "Resource temporarily unavailable" error. The error code 11 (EAGAIN) indicates the resource is temporarily busy. This commonly happens when Ubuntu's automatic updates run in the background at the same time you try to manually update packages, or when a previous apt/dpkg operation crashed without releasing the lock properly.
The most common cause is Ubuntu's automatic background update process. Try waiting 5-15 minutes for it to finish.
Check if any apt processes are running:
ps aux | grep -E 'apt|dpkg'If you see processes like 'unattended-upgrades' or 'apt-get update', let them complete. You can also check the apt logs:
sudo tail -f /var/log/apt/history.logOnce you don't see any apt-related processes, your command should work.
If waiting doesn't work, check which process is holding the lock files:
sudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lockThis will show you the process ID (PID) holding each lock. The output shows the process name and ID. If you see a process that's stuck or no longer needed, you can proceed to the next step.
Only do this if you've confirmed a stalled process is holding the lock. Never kill a process that's actively installing critical system updates.
If the process is stuck or appears to be old (check with ps aux), terminate it:
sudo kill -9 <PID>Replace <PID> with the actual process ID from the previous step. After killing it, retry your apt command.
Warning: If the process is actively installing packages, killing it could leave your system in a broken state. Use this only as a last resort for stuck processes.
If apt operations were interrupted, dpkg's internal state may be corrupted. Repair it with:
sudo dpkg --configure -aThis command reconfigures any partially installed packages and fixes missing dependencies. Follow any prompts on screen. After this completes, try your apt command again.
If none of the above works, a reboot will clear all locks and running processes:
sudo rebootWait for the system to fully restart (2-3 minutes), then try your apt command. Upon boot, if there are pending package operations, apt will resume or complete them automatically.
For systems with high load or those using unattended-upgrades, you can check the status of automatic updates with 'systemctl status apt-daily-upgrade.service'. On headless servers, disable the Software Center daemon entirely to prevent automatic background updates from locking dpkg.
On rare occasions, if lock files remain after a crash, you may need to manually remove them with 'sudo rm /var/lib/dpkg/lock*' and 'sudo rm /var/lib/apt/lists/lock', but only as an absolute last resort after confirming no processes are using dpkg. Removing lock files without cause can corrupt your package database.
dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Sub-process /usr/bin/dpkg returned an error code (2)
How to fix "Sub-process /usr/bin/dpkg returned an error code (2)" in APT
dpkg-divert: error: rename involves overwriting 'path' with different file
How to fix dpkg-divert rename conflicts in APT
E: Sub-process /usr/bin/dpkg returned an error code (1) during kernel installation
How to fix "dpkg returned an error code (1)" in APT kernel installation
dpkg: dependency problems prevent configuration of triggers
dpkg: dependency problems prevent configuration of triggers in apt