← Back to Error Index
root@linuxfix:~/could_not_get_lock$
could not get lock
E Could not get lock var lib dpkg lock

Solutions

Prerequisites: Start by updating your system to resolve common issues and ensure the solutions provided below are compatible with your current environment.
check_latest_version && sudo apt update && sudo apt upgrade -y
Wait for process to complete

Check if legitimate process is running:

ps aux | grep -i apt
ps aux | grep -i dpkg
sudo lsof /var/lib/dpkg/lock
Kill blocking processes

Terminate stuck package processes:

sudo killall apt apt-get
sudo killall dpkg
sudo pkill -f unattended-upgrade
Remove lock files

Remove stale lock files:

sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*
Warning: Only remove locks if no package processes are actually running.

What is could not get lock?

Another package management process is running, preventing new package operations from starting.

Common scenarios: Multiple package managers running, automatic updates in progress, or crashed package manager holding lock.

Common Causes

  • Another apt/dpkg process running
  • Automatic updates in background
  • Package manager crashed with lock held
  • System startup scripts using package manager
  • GUI package manager open

Debugging Tips

sudo fuser -v /var/lib/dpkg/lock
systemctl status unattended-upgrades
ls -la /var/lib/dpkg/lock*
ps -ef | grep -E "(apt|dpkg)"

Prevention

  • Wait for automatic updates to finish
  • Close GUI package managers
  • Use single package manager at a time
  • Monitor long-running updates
apt dpkg lock concurrent