Errors Updating Packages on Linux: How to Fix Them
Fix the most common failures when updating packages or the system on Linux distributions.
"Could not get lock"
Another update process is still running or got stuck.
sudo killall apt apt-get
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*
sudo dpkg --configure -a
Broken dependencies
sudo apt --fix-broken install
Repository giving a 404 error or similar
This usually indicates an outdated or discontinued third-party
repository. Check /etc/apt/sources.list and the files
under /etc/apt/sources.list.d/ — remove or comment out
the line for the failing repository if you no longer need it.
Warning: before manually deleting lock files, confirm no update is genuinely still running — only do this if you are sure the previous process got stuck, not simply taking a while.
Frequently asked questions
Is it safe to delete apt's lock files?
Only if you confirm no update process is genuinely still running — deleting them while an update is in progress can leave the package system in an inconsistent state.
What do I do if a third-party repository gives a 404 error?
Check the files under /etc/apt/sources.list.d/ and remove or comment out the line for that repository if it is no longer available or you no longer need it.