Linux dpkg-lockedMedium

dpkg locked error: how to unlock the package manager

This article explains what the dpkg locked error is in Linux and provides several proven solutions to resume package management.

Updated at February 17, 2026
5-10 minutes
Medium
FixPedia Team
Применимо к:Ubuntu 20.04+Debian 10+Linux Mint 20+

What the "dpkg locked" Error Means

The dpkg locked (or Could not get lock) error occurs when the dpkg (or apt) package management system cannot access its database because another process is already using it. Typical error messages:

E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (apt)
E: Could not get lock /var/lib/dpkg/lock. It is held by process 5678 (dpkg)

This error appears when attempting commands like sudo apt update, sudo apt install <package>, or sudo dpkg -i <file.deb>. It blocks any package installation, removal, or update operations until the lock is released.

Common Causes

  1. Parallel package manager execution: You started apt in the terminal while simultaneously using a graphical package manager (Software Center, Synaptic) or another instance of apt/dpkg.
  2. Interrupted operation: A previous installation or update was forcibly stopped (e.g., via Ctrl+C, closing the terminal, or a system crash), leaving a lock-file behind.
  3. Background processes: Automatic updates (e.g., via unattended-upgrades) or other system services using dpkg/apt.
  4. Stale lock-file: In rare cases, a lock-file might remain due to permission issues or filesystem corruption.

Solutions

Method 1: Terminate Conflicting Processes

First, identify which process holds the lock.

  1. Find the PID (process ID) using:
    sudo lsof /var/lib/dpkg/lock-frontend
    sudo lsof /var/lib/dpkg/lock
    

    If the command returns a process (e.g., apt or dpkg), note its PID.
  2. Alternatively, use:
    ps aux | grep -E 'apt|dpkg'
    

    Look for processes like apt-get, apt-systemd, dpkg.
  3. Safely terminate the process:
    • If the process is active (installation in progress), wait for it to finish.
    • If the process is "stuck" or you're sure it's not needed, kill it:
      sudo kill <PID>
      
      If that doesn't work, use force kill:
      sudo kill -9 <PID>
      
    • You can kill all apt and dpkg processes (use caution!):
      sudo pkill -9 apt
      sudo pkill -9 dpkg
      
  4. After terminating processes, try your command again (e.g., sudo apt update).

Method 2: Manually Remove Lock Files

If no processes are found or the error persists, lock-files likely remain from an interrupted operation.

  1. Ensure no active dpkg/apt processes (repeat steps from Method 1).
  2. Remove lock files:
    sudo rm /var/lib/dpkg/lock
    sudo rm /var/lib/dpkg/lock-frontend
    sudo rm /var/cache/apt/archives/lock
    sudo rm /var/lib/apt/lists/lock
    

    ⚠️ Important: Only remove lock files if you're certain no dpkg/apt processes are running. Otherwise, you risk damaging the package database.

  3. After removal, reconfigure dpkg to complete any unfinished operations:
    sudo dpkg --configure -a
    
  4. You can now use apt or dpkg again.

Method 3: Reboot the System

If previous methods fail or you're unsure, a simple reboot often resolves the issue:

  1. Restart the system:
    sudo reboot
    

    During boot, all processes will terminate, and lock files will be automatically released.
  2. After logging in, try the apt command again.

Method 4: Fix Permissions (If Needed)

In rare cases, the issue may be incorrect permissions on lock files or directories.

  1. Check permissions on the /var/lib/dpkg/ directory:
    ls -ld /var/lib/dpkg/
    

    The owner should be root:root, permissions drwxr-xr-x.
  2. If permissions are incorrect, fix them:
    sudo chown root:root /var/lib/dpkg/
    sudo chmod 755 /var/lib/dpkg/
    
  3. Repeat lock file removal (Method 2) and reconfiguration.

Prevention

To avoid recurring dpkg locked errors:

  • Never run multiple package managers simultaneously. Close all graphical utilities (Software Center, Synaptic) before using apt in the terminal.
  • Do not interrupt installation/removal operations (e.g., with Ctrl+C) unless absolutely critical. Wait for completion.
  • Regularly update your system (sudo apt update && sudo apt upgrade) to minimize unfinished operations.
  • Configure automatic updates (if using unattended-upgrades) so they don't conflict with manual actions. Ensure the service runs correctly:
    sudo systemctl status unattended-upgrades
    
  • When using automation scripts, add lock-file checks via flock or similar to prevent concurrent runs.

If the error occurs frequently without an obvious cause, check system logs for other issues:

sudo journalctl -xe | grep -i dpkg

F.A.Q.

Why does the dpkg locked error occur?
Can I ignore this error and continue?
How can I prevent the dpkg locked error from recurring?
What if the lock file won't delete?

Hints

Find processes holding the lock
Terminate the found processes
Manually remove the lock files
Reconfigure dpkg

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community