How to fix dpkg: error: dpkg frontend lock was locked by another process in APT

APTBEGINNERMEDIUMUpdated Sep 27, 2026ยท 506 views

This error occurs when the package manager (apt or dpkg) is being used by another process, preventing new installations or updates. The system uses lock files to prevent simultaneous access that could corrupt the package database.

Quick fix

Fixes dpkg: error: dpkg frontend lock was locked by another process

ps aux | grep -i apt
ps aux | grep -i dpkg
  1. Wait for the background process to finish
  2. Identify which process holds the lock
  3. Safely terminate the blocking process (if necessary)
  4. Set a timeout for apt operations (optional)
apt โ€” error
ps aux | grep -i apt
ps aux | grep -i dpkg
dpkg: error: dpkg frontend lock was locked by another process

What this error means

The dpkg package manager uses lock files to ensure only one process accesses the package database at a time. When you try to run apt-get, apt, or dpkg while another process is using these tools, the new process gets locked out and cannot proceed. This commonly happens because: - The Ubuntu/Debian system is running automatic package updates in the background - Another terminal window or process is running apt/apt-get commands - A previous apt process crashed and left the system in a locked state - A package manager tool is hanging or stuck The lock files are located at /var/lib/dpkg/lock, /var/lib/apt/lists/lock, and /var/cache/apt/archives/lock to prevent database corruption.

Typical symptoms

  • Any apt or dpkg command fails immediately with the "locked by another process" error
  • System cannot install, update, or remove packages
  • Ubuntu automatic updates appear to be stuck or hung in the background
  • Error persists even after waiting several minutes

Common causes

  1. Ubuntu/Debian system is running automatic package updates in the background (most common)
  2. Another terminal or process is actively running apt, apt-get, or dpkg commands
  3. A previous apt/dpkg process crashed and left the system in a locked state without proper cleanup
  4. System package manager (GNOME Software, Software Center, etc.) is updating packages
  5. The /var/lib/dpkg directory is on a full disk, preventing lock file operations

How to fix "dpkg: error: dpkg frontend lock was locked by another process"

1Wait for the background process to finish

The simplest and most reliable solution is to wait for whatever process holds the lock to complete. Ubuntu typically runs automatic updates in the background.

Run this command to check if there are any apt/dpkg processes still running:

bash
ps aux | grep -i apt
ps aux | grep -i dpkg

If you see processes listed, wait 10-15 minutes for them to complete. Check again with the same commands until they're gone, then try your apt command again.

2Identify which process holds the lock

If waiting doesn't work or you want to see exactly what's holding the lock, use the lsof command to identify the process ID:

bash
sudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lock

This will show you the process ID (PID) of any process currently holding each lock file. Note these PIDs for the next step.

3Safely terminate the blocking process (if necessary)

If you've confirmed a process is stuck and won't finish, use the fuser command to safely terminate it:

bash
sudo fuser -vki -TERM /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock

This command will prompt you to confirm termination. The -TERM flag sends a graceful termination signal (safer than kill -9).

After terminating any processes, reconfigure dpkg to finalize any pending operations:

bash
sudo dpkg --configure --pending

This ensures any interrupted package configuration is completed and the database is consistent.

4Set a timeout for apt operations (optional)

For better resilience in scripts or automated environments, you can tell apt to wait for the lock with a timeout:

bash
sudo apt-get -o DPkg::Lock::Timeout=300 update
sudo apt-get -o DPkg::Lock::Timeout=300 install package-name

The timeout value is in seconds (300 = 5 minutes). This tells apt to wait up to 5 minutes for the lock to be released before giving up, rather than failing immediately.

Advanced notes

Why removing lock files is dangerous: Many online guides suggest deleting the lock files directly (/var/lib/dpkg/lock, /var/lib/apt/lists/lock, /var/cache/apt/archives/lock). The Debian team strongly opposes this approach because lock files exist to prevent simultaneous access that would corrupt the package manager database and potentially damage your entire system. Only remove lock files as an absolute last resort, and always run sudo dpkg --configure -a immediately afterward to restore consistency.

On systems with full /var partition: If disk space is critically low in /var/lib, the lock mechanism may fail. Check disk usage with df -h /var and clear package cache if needed: sudo apt-get clean

In container/CI environments: Docker and CI systems sometimes inherit lock files from previous runs. Always clean lock files in container entry points before running apt: rm -f /var/lib/apt/lists/lock /var/cache/apt/archives/lock /var/lib/dpkg/lock*

Frequently asked questions

What does "dpkg: error: dpkg frontend lock was locked by another process" mean?
The dpkg package manager uses lock files to ensure only one process accesses the package database at a time. When you try to run apt-get, apt, or dpkg while another process is using these tools, the new process gets locked out and cannot proceed. This commonly happens because: - The Ubuntu/Debian system is running automatic package updates in the background - Another terminal window or process is running apt/apt-get commands - A previous apt process crashed and left the system in a locked state - A package manager tool is hanging or stuck The lock files are located at /var/lib/dpkg/lock, /var/lib/apt/lists/lock, and /var/cache/apt/archives/lock to prevent database corruption.
How do I fix "dpkg: error: dpkg frontend lock was locked by another process"?
This error occurs when the package manager (apt or dpkg) is being used by another process, preventing new installations or updates. The system uses lock files to prevent simultaneous access that could corrupt the package database.
What causes "dpkg: error: dpkg frontend lock was locked by another process"?
Ubuntu/Debian system is running automatic package updates in the background (most common) Another terminal or process is actively running apt, apt-get, or dpkg commands A previous apt/dpkg process crashed and left the system in a locked state without proper cleanup
Is the "dpkg: error: dpkg frontend lock was locked by another process" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading