This error occurs when apt or dpkg cannot read the package status file due to insufficient permissions. The fix is typically to run commands with sudo, check file permissions, or clear stale lock files that are blocking access.
The /var/lib/dpkg/status file is a critical database that stores information about all installed packages on your system. When apt or dpkg cannot open this file, it means your user account lacks the necessary permissions to read it. This error (errno 13) specifically indicates a permission issue. The dpkg package manager requires root/superuser access to read and modify system package databases. This error commonly occurs when users attempt to run apt or apt-get commands without sudo, or when the file permissions have been incorrectly modified.
The most common fix is to simply prefix your apt command with sudo:
sudo apt update
sudo apt install package-name
sudo apt-get upgradeThe sudo command grants you temporary root/superuser privileges needed to access the dpkg database. Without it, your regular user account cannot read the protected system files.
Another process might be holding a lock on the dpkg database. Check if any other apt or package manager is running:
sudo lsof /var/lib/dpkg/lock-frontendIf output is shown, wait for that process to complete. You can also check:
sudo lsof /var/lib/dpkg/lock
sudo lsof /var/cache/apt/archives/lockIf you see a process ID, you can wait for it to finish or carefully terminate it with:
sudo kill -9 <PID>If no process is using the locks, stale lock files might be blocking access. Remove them:
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/dpkg/lock
sudo rm /var/cache/apt/archives/lockThen reconfigure the dpkg database:
sudo dpkg --configure -a
sudo apt updateIf the issue persists, the dpkg directory permissions may be incorrect. Fix them:
sudo chown root:root /var/lib/dpkg
sudo chmod 755 /var/lib/dpkg
sudo chown root:root /var/lib/dpkg/status
sudo chmod 644 /var/lib/dpkg/statusThese commands ensure the dpkg directory and status file are owned by root with the correct permissions.
If the status file is corrupted, restore it from the automatic backup:
sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status
sudo apt updateAlternatively, if that backup doesn't exist, try:
sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status
sudo apt updateIf a package installation was interrupted, reconfigure broken packages:
sudo dpkg --configure -a
sudo apt --fix-broken installThis attempts to complete any incomplete package configurations and fixes dependencies.
The /var/lib/dpkg directory is a critical system directory that should always be owned by root with permissions 755. The status file itself should have permissions 644. If you're working inside a Docker container or chroot environment, you might need to reinstall the base system packages if the dpkg database is severely corrupted. On systems with SELinux enabled, the context labels on /var/lib/dpkg files might also need to be restored with sudo restorecon -r /var/lib/dpkg. For fresh installations or container images, you may need to reinstall the base system with sudo apt install --reinstall base-files base-passwd.
dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Sub-process /usr/bin/dpkg returned an error code (2)
How to fix "Sub-process /usr/bin/dpkg returned an error code (2)" in APT
dpkg-divert: error: rename involves overwriting 'path' with different file
How to fix dpkg-divert rename conflicts in APT
E: Sub-process /usr/bin/dpkg returned an error code (1) during kernel installation
How to fix "dpkg returned an error code (1)" in APT kernel installation
dpkg: dependency problems prevent configuration of triggers
dpkg: dependency problems prevent configuration of triggers in apt