How to Safely Bypass Ubuntu ‘Could Not Get Lock /var/lib/dpkg/lock’ (Fix APT Error)

When you try to install a new program or run a system update using the terminal in Ubuntu Linux (e.g., by typing sudo apt upgrade), the system might instantly reject your command. Instead of installing the software, it spits out a frustrating red error message: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable).

This error means another software management tool is currently running in the background. To prevent two programs from trying to install software at the exact same time (which would completely destroy your operating system), Ubuntu creates a temporary “lock” file. Usually, this means the automated background updater is running. If you wait five minutes, the lock usually clears. However, if a previous installation crashed, the lock file becomes permanently stuck. You must manually bypass and destroy the orphaned lock.

How to Safely Bypass the Ubuntu apt/dpkg Lock Error

You must find the crashed process holding the lock and then manually delete the lock files.

  1. Open your Terminal application (Ctrl + Alt + T).
  2. First, we need to ensure no legitimate update processes are actually running. Type the following command and press Enter to aggressively kill any stuck APT processes: sudo killall apt apt-get
  3. If the terminal says “no process found,” that confirms the previous installation crashed and left a ghost lock file behind.
  4. Next, we will manually delete the physical lock files. Type the following three commands, pressing Enter after each one. (Type your password if prompted): sudo rm /var/lib/apt/lists/lock sudo rm /var/cache/apt/archives/lock sudo rm /var/lib/dpkg/lock*
  5. Finally, because a previous installation likely crashed halfway through, we must force Ubuntu to repair any broken packages before we try installing anything new. Type this command and press Enter: sudo dpkg --configure -a

Once the dpkg command finishes running, your package manager is completely repaired and unlocked. You can now type your original sudo apt install command, and it will execute perfectly without the lock error.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.