How to fix E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) in APT

APTBEGINNERMEDIUMUpdated Dec 29, 2025· 335 views

This error occurs when attempting to run apt or dpkg commands without sufficient permissions. The /var/lib/dpkg/lock-frontend file requires root access. Using sudo, waiting for background updates, or checking for blocking processes resolves this issue.

Quick fix

Fixes 13

sudo apt update
sudo apt install package-name
sudo apt upgrade
  1. Use sudo for package management commands
  2. Wait for automatic background updates to finish
  3. Check what process is holding the lock
  4. Kill stuck processes (if necessary)
apt — error
sudo apt update
sudo apt install package-name
sudo apt upgrade
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)

What this error means

When you see "E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)", it means the apt or dpkg package manager is unable to access the lock file that controls simultaneous access to package installation operations. The error code 13 is EACCES (Error ACcess denied), indicating a file permissions problem. The /var/lib/dpkg/lock-frontend file is owned by root and is used to prevent multiple package managers from running simultaneously, which could corrupt the system. This typically happens when: - You're running apt commands as a regular user instead of root - Another process (like automatic updates) is holding the lock - The system is busy with background package management operations - The lock file has incorrect permissions

Typical symptoms

  • apt update, apt install, or apt upgrade commands fail immediately
  • Error mentions /var/lib/dpkg/lock-frontend or /var/lib/apt/lists/lock
  • Commands work fine when prefixed with sudo but fail without it
  • Automatic background updates are running (on Ubuntu/Debian systems)

Common causes

  1. User attempting to run apt commands without sudo privileges (most common)
  2. Another package manager process is running in the background (automatic updates, unattended-upgrades)
  3. Lock file left behind from a crashed or interrupted package operation
  4. Permissions on /var/lib/dpkg or lock files are incorrectly set
  5. A stuck process holding the lock file indefinitely

How to fix "E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)"

1Use sudo for package management commands

The simplest and most common fix is to prefix your apt commands with sudo to run them with administrative privileges:

bash
sudo apt update
sudo apt install package-name
sudo apt upgrade

This grants the apt command the necessary permissions to access the dpkg lock files. Always use sudo when running any apt or dpkg commands that modify the system.

2Wait for automatic background updates to finish

Ubuntu and Debian systems often run automatic background updates that lock the package manager. Wait 10-15 minutes for these processes to complete naturally before trying again.

You can check if apt is currently running:

bash
ps aux | grep -i apt

If you see unattended-upgrade or apt processes, let them finish. This is the safest approach.

3Check what process is holding the lock

If background updates don't seem to be the issue, check what process is holding the lock file:

bash
sudo lsof /var/lib/dpkg/lock-frontend

This command shows which process (if any) has the lock file open. If no output appears, the lock file exists but isn't being used by any running process—likely a leftover from a previous operation.

You can also check for any stuck apt processes:

bash
ps aux | grep apt
4Kill stuck processes (if necessary)

If a process is hanging and preventing package operations, you can terminate it. First, identify the PID from the previous step, then:

bash
# For graceful termination
sudo kill PID

# For forced termination (if the process won't stop)
sudo kill -9 PID

Replace PID with the actual process ID. After killing the process, run:

bash
sudo dpkg --configure -a

This command completes any interrupted package installations and cleans up the system state.

5Remove stale lock files (last resort)

Only do this if you're certain no package manager is running. Removing lock files while apt is active can corrupt your package database.

First, verify no apt processes are running:

bash
sudo lsof /var/lib/dpkg/lock-frontend

If no output appears, you can safely remove the stale lock files:

bash
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend

Then reconfigure dpkg:

bash
sudo dpkg --configure -a
sudo apt update
6Reboot if all else fails

If the lock persists despite trying the above steps, rebooting the system will clear any stuck processes and lock files:

bash
sudo reboot

After rebooting, the lock file issue should be resolved and you can run apt commands normally with sudo.

Advanced notes

The /var/lib/dpkg/ directory maintains the state of the Debian package system. The lock file (/var/lib/dpkg/lock-frontend) ensures that only one package manager process modifies the system at a time.

File permissions should typically be:
- /var/lib/dpkg/lock-frontend: 644 (-rw-r--r--)
- /var/lib/dpkg/: 755 (drwxr-xr-x)
- Both owned by root user and root group

If you've accidentally changed permissions on these files, restore them with:

bash
sudo chmod 644 /var/lib/dpkg/lock-frontend
sudo chmod 755 /var/lib/dpkg
sudo chown root:root /var/lib/dpkg/lock-frontend

On systems with unattended-upgrades enabled, the daemon runs periodic automatic updates. You can check its status with:

bash
sudo systemctl status unattended-upgrades

To see when it last ran:

bash
sudo cat /var/log/unattended-upgrades/unattended-upgrades.log

Frequently asked questions

What does "13" mean?
When you see "E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)", it means the apt or dpkg package manager is unable to access the lock file that controls simultaneous access to package installation operations. The error code 13 is EACCES (Error ACcess denied), indicating a file permissions problem. The /var/lib/dpkg/lock-frontend file is owned by root and is used to prevent multiple package managers from running simultaneously, which could corrupt the system.
How do I fix "13"?
This error occurs when attempting to run apt or dpkg commands without sufficient permissions. The /var/lib/dpkg/lock-frontend file requires root access. Using sudo, waiting for background updates, or checking for blocking processes resolves this issue.
What causes "13"?
User attempting to run apt commands without sudo privileges (most common) Another package manager process is running in the background (automatic updates, unattended-upgrades) Lock file left behind from a crashed or interrupted package operation
Is the "13" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading