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.
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
The simplest and most common fix is to prefix your apt commands with sudo to run them with administrative privileges:
sudo apt update
sudo apt install package-name
sudo apt upgradeThis 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.
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:
ps aux | grep -i aptIf you see unattended-upgrade or apt processes, let them finish. This is the safest approach.
If background updates don't seem to be the issue, check what process is holding the lock file:
sudo lsof /var/lib/dpkg/lock-frontendThis 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:
ps aux | grep aptIf a process is hanging and preventing package operations, you can terminate it. First, identify the PID from the previous step, then:
# For graceful termination
sudo kill PID
# For forced termination (if the process won't stop)
sudo kill -9 PIDReplace PID with the actual process ID. After killing the process, run:
sudo dpkg --configure -aThis command completes any interrupted package installations and cleans up the system state.
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:
sudo lsof /var/lib/dpkg/lock-frontendIf no output appears, you can safely remove the stale lock files:
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-frontendThen reconfigure dpkg:
sudo dpkg --configure -a
sudo apt updateIf the lock persists despite trying the above steps, rebooting the system will clear any stuck processes and lock files:
sudo rebootAfter rebooting, the lock file issue should be resolved and you can run apt commands normally with sudo.
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:
sudo chmod 644 /var/lib/dpkg/lock-frontend
sudo chmod 755 /var/lib/dpkg
sudo chown root:root /var/lib/dpkg/lock-frontendOn systems with unattended-upgrades enabled, the daemon runs periodic automatic updates. You can check its status with:
sudo systemctl status unattended-upgradesTo see when it last ran:
sudo cat /var/log/unattended-upgrades/unattended-upgrades.logE: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT