How to fix dpkg: error: cannot remove old file '/path': Permission denied in APT

APTBEGINNERMEDIUMUpdated Dec 29, 2025ยท 234 views

This error occurs when dpkg cannot remove outdated package files due to insufficient permissions. The file or parent directory ownership/permissions prevent the deletion operation needed during package installation or upgrade.

Quick fix

Fixes EACCES

# Instead of: apt update
sudo apt update

# Instead of: apt-get install package
sudo apt-get install package

# Instead of: dpkg -i package.deb
sudo dpkg -i package.deb

# To upgrade packages
sudo apt upgrade

# To fix broken packages
sudo apt --fix-broken install
  1. Run the command with sudo to gain root privileges
  2. Remove dpkg lock files if another process is holding them
  3. Fix permissions on dpkg directories
  4. Check for and remove immutable file attributes
apt โ€” error
# Instead of: apt update
sudo apt update
# Instead of: apt-get install package
sudo apt-get install package
# Instead of: dpkg -i package.deb
sudo dpkg -i package.deb
# To upgrade packages
sudo apt upgrade
# To fix broken packages
sudo apt --fix-broken install
dpkg: error: cannot remove old file '/path': Permission denied

What this error means

The "dpkg: error: cannot remove old file" permission denied error indicates that the dpkg package manager lacks the necessary permissions to delete existing files during a package installation, upgrade, or removal operation. This typically happens when: - The dpkg process runs without sufficient privileges (not as root) - Files or directories have restrictive permissions that prevent deletion - The parent directory permissions prevent modifications - Files have immutable attributes set by the filesystem - Incorrect ownership of files in the dpkg database or cache directories dpkg needs write access to the parent directory to remove old versions of files being upgraded or to clean up files from removed packages.

Typical symptoms

  • apt or apt-get upgrade fails with "cannot remove old file" error
  • Package installation halts midway through
  • Permission denied message appears during dpkg processing
  • Upgrade operations fail on specific files or directories
  • Error message includes the full path to the problematic file
  • Running the same command with sudo succeeds
  • apt reports broken dependencies due to incomplete upgrade

Common causes

  1. Running apt or dpkg without root privileges (not using sudo)
  2. Incorrect file permissions on files in /var/lib/dpkg or /var/cache/apt directories
  3. Parent directory permissions preventing file deletion
  4. Files with immutable attribute set (chattr +i)
  5. Incorrect ownership of files (not owned by root)
  6. Filesystem mounted as read-only in specific locations
  7. Another process (like apt-get or dpkg) already running and locking files
  8. SELinux or AppArmor restrictions preventing deletion
  9. Third-party tools or scripts modifying file permissions in apt directories

How to fix "dpkg: error: cannot remove old file '/path': Permission denied"

1Run the command with sudo to gain root privileges

The most common cause is attempting to run apt or dpkg without root privileges. Always use sudo:

bash
# Instead of: apt update
sudo apt update

# Instead of: apt-get install package
sudo apt-get install package

# Instead of: dpkg -i package.deb
sudo dpkg -i package.deb

# To upgrade packages
sudo apt upgrade

# To fix broken packages
sudo apt --fix-broken install

Root privileges are required because dpkg modifies system files in protected directories like /var/lib/dpkg, /var/cache/apt, and /usr.

2Remove dpkg lock files if another process is holding them

Sometimes lock files remain from a previous interrupted operation. Remove them to allow dpkg to proceed:

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

# Reconfigure dpkg after removing locks
sudo dpkg --configure -a

# Update package lists
sudo apt update

Lock files prevent concurrent dpkg operations. Removing stale locks allows the package manager to resume normal operation.

3Fix permissions on dpkg directories

Verify and correct permissions on critical dpkg directories:

bash
# Check current permissions
ls -la /var/lib/dpkg
ls -la /var/cache/apt

# Fix ownership and permissions
sudo chown -R root:root /var/lib/dpkg
sudo chmod 755 /var/lib/dpkg
sudo chmod 644 /var/lib/dpkg/status
sudo chmod 644 /var/lib/dpkg/status-old

sudo chown -R root:root /var/cache/apt
sudo chmod 755 /var/cache/apt
sudo chmod 755 /var/cache/apt/archives

Files should be owned by root and have standard Linux permissions (755 for directories, 644 for files).

4Check for and remove immutable file attributes

Files can have the immutable attribute set, preventing deletion even by root. Check and remove it:

bash
# Check if the problematic file has immutable attribute
sudo lsattr /path/to/problematic/file

# If the output shows 'i' flag, remove it
sudo chattr -i /path/to/problematic/file

# For directories and contents
sudo chattr -R -i /var/lib/dpkg
sudo chattr -R -i /var/cache/apt

# Retry the failed operation
sudo apt update
sudo apt --fix-broken install

The 'i' attribute makes files immutable. This is rarely set intentionally but can occur due to security tools or system configuration.

5Force dpkg to reconfigure all packages

After fixing permissions, reconfigure dpkg to complete any interrupted installations:

bash
# Configure packages that are not fully configured
sudo dpkg --configure -a

# If there are broken dependencies
sudo apt --fix-broken install

# Or try this if --fix-broken is not enough
sudo apt --fix-missing install

# Finally, run a clean update
sudo apt clean
sudo apt update

This command processes partially installed or configured packages and resolves dependency issues.

6Boot into recovery mode if regular fixes fail

For persistent permission issues, boot into recovery mode where the root filesystem is mounted read-write but fewer processes are running:

1. Restart your system and enter the GRUB boot menu (hold Shift during startup)
2. Select "Recovery mode" or a kernel with "(recovery mode)" in the name
3. When prompted, select "Drop to root shell prompt"
4. Run these commands in the recovery shell:

bash
# Remount filesystem as read-write
mount -o remount,rw /

# Fix permissions
chown -R root:root /var/lib/dpkg
chmod 755 /var/lib/dpkg

# Reconfigure dpkg
dpkg --configure -a

# Exit recovery mode
exit

# Choose "Resume normal boot"

Recovery mode provides a minimal environment where you can safely fix critical system issues.

Advanced notes

SELinux and AppArmor Contexts: If your system uses SELinux or AppArmor, these security frameworks may prevent file deletion even with correct permissions. Check security logs with sudo ausearch -m avc (SELinux) or sudo grep apparmor /var/log/syslog (AppArmor).

Filesystem Issues: Use sudo mount | grep /var to verify that /var is not mounted read-only. If it is, remount with read-write permissions: sudo mount -o remount,rw /var.

Checking File Descriptor Locks: Use sudo lsof | grep /path/to/file to see if any process has the problematic file open. Close those processes before removing the file.

Disk Space and Inodes: Occasionally, permission errors mask underlying disk space or inode exhaustion. Check with df -h and df -i. If inodes are full, you may need to remove files to free space.

Multiarch Issues: On systems with multiarch support, different package architectures (amd64, i386) can have permission conflicts. Repair with sudo apt install -f or sudo apt --fix-broken install.

Complete Package Cache Cleanup: If problems persist, you can safely remove the entire apt cache and rebuild it:

bash
sudo apt clean
sudo apt autoclean
sudo apt update

Frequently asked questions

What does "EACCES" mean?
The "dpkg: error: cannot remove old file" permission denied error indicates that the dpkg package manager lacks the necessary permissions to delete existing files during a package installation, upgrade, or removal operation. This typically happens when: - The dpkg process runs without sufficient privileges (not as root) - Files or directories have restrictive permissions that prevent deletion - The parent directory permissions prevent modifications - Files have immutable attributes set by the filesystem - Incorrect ownership of files in the dpkg database or cache directories dpkg needs write access to the parent directory to remove old versions of files being upgraded or to clean up files from removed packages.
How do I fix "EACCES"?
This error occurs when dpkg cannot remove outdated package files due to insufficient permissions. The file or parent directory ownership/permissions prevent the deletion operation needed during package installation or upgrade.
What causes "EACCES"?
Running apt or dpkg without root privileges (not using sudo) Incorrect file permissions on files in /var/lib/dpkg or /var/cache/apt directories Parent directory permissions preventing file deletion
Is the "EACCES" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading