How to fix dpkg: warning: unable to delete old directory '/path': Directory not empty in APT

APTBEGINNERLOWUpdated Oct 19, 2026· 467 views

This warning appears when dpkg cannot fully delete a directory during package removal or upgrade because the directory still contains files. This is usually harmless and occurs when package maintainers add new files that older versions didn't account for. The directory can typically be manually cleaned up or left as-is since it doesn't prevent the package operation from completing.

Quick fix

Fixes dpkg: warning: unable to delete old directory '/path': Directory not empty

ls -la /path
  1. Understand the warning is typically harmless
  2. Check what files remain in the directory
  3. Use "apt purge" instead of "apt remove" for clean removal
  4. Manually remove orphaned directories (if safe)
apt — error
ls -la /path
dpkg: warning: unable to delete old directory '/path': Directory not empty

What this error means

When dpkg removes or upgrades a package, it attempts to delete directories that were part of the old package structure. If the directory contains leftover files (especially newer files added in recent package versions), dpkg cannot delete the non-empty directory and emits this warning. This typically happens with system directories like /etc, /usr/lib, or /var that contain configuration files or plugins beyond what dpkg owns. The warning indicates that while the package files were removed successfully, some directory cleanup couldn't be completed.

Typical symptoms

  • Warning message appears during apt install, apt upgrade, or apt remove operations
  • Package operation continues despite the warning
  • Directories remain on the filesystem after package removal
  • Multiple warnings about different directories during a single upgrade
  • Warnings reference system directories like /etc, /usr/lib, /lib, or /var

Common causes

  1. Directory contains files that don't belong to the package being removed
  2. User-added or plugin files exist in the directory that dpkg cannot remove
  3. Third-party software has added files to system directories
  4. Configuration files remain after using "apt remove" instead of "apt purge"
  5. Package maintainer changes in recent versions altered the directory structure
  6. Orphaned files from previously removed but not purged packages
  7. Manual modifications to system directories that package doesn't own

How to fix "dpkg: warning: unable to delete old directory '/path': Directory not empty"

1Understand the warning is typically harmless

This warning is generally not a problem and does not prevent your package operation from completing. dpkg has already removed the package files successfully; it simply couldn't delete the directory because it's not empty. The warning is informational rather than critical. You can safely continue using your system and the package.

2Check what files remain in the directory

If you want to investigate what's left in the directory, use ls to view its contents. Replace /path with the actual directory from the warning message:

bash
ls -la /path

This will show you what files or subdirectories are still present. If the directory is empty but the warning still occurred, the issue may have already resolved itself.

3Use "apt purge" instead of "apt remove" for clean removal

If you're removing a package and want to ensure all configuration files and related directories are cleaned up, use purge instead of remove:

bash
sudo apt purge package-name

Purge removes both the package and all associated configuration files. Use apt purge after apt remove on packages you're no longer using:

bash
sudo apt remove package-name
sudo apt purge package-name

This is more thorough than remove alone but may still not delete directories if they contain other non-owned files.

4Manually remove orphaned directories (if safe)

If you've verified that the leftover directory contains only orphaned files and nothing important, you can manually remove it. First, verify the directory is safe to delete by checking its contents:

bash
sudo ls -la /path

If the directory is empty or contains only files you don't need:

bash
sudo rmdir /path

For directories with contents, use:

bash
sudo rm -rf /path

Be extremely careful with rm -rf as it irreversibly deletes files. Only use this on directories you fully understand and can verify are safe to remove.

5Clean up using apt autoremove and apt autoclean

Run the apt cleaning commands to remove unused dependencies and temporary files:

bash
sudo apt autoremove
sudo apt autoclean

apt autoremove removes packages that were automatically installed but are no longer needed by any installed package. apt autoclean clears the apt package cache of old package files. These won't directly fix directory cleanup but help maintain a clean system.

6Check for and remove unpurged packages

List all packages that have been removed but not purged (marked as "rc" in dpkg):

bash
dpkg --list | grep '~rc'

To purge all remaining unpurged packages at once:

bash
sudo apt purge ~c

Or purge specific unpurged packages:

bash
sudo apt purge package-name

This removes configuration files and may clean up orphaned directories that weren't handled during the initial removal.

Advanced notes

This warning is a known long-standing dpkg behavior documented in Debian bug reports. It occurs because dpkg uses a "declaim ownership" model—it can only delete directories it explicitly owns in the package manifest. When package maintainers modify the structure across versions, directories that were tracked in old packages may contain new files added by newer versions, causing the cleanup to fail. Distribution transitions (like /usr-merge on modern Debian systems) can also trigger these warnings across many packages. System administrators may find it acceptable to leave these directories in place, as they don't interfere with system operation. For production systems, the conservative approach is to document which directories have this warning and only remove them after verification that no running services depend on them. Some package managers (like apt with full-text search) maintain package file ownership databases in /var/lib/dpkg/info/ which can help identify what package "owns" a file. Containers and clean system installations won't see these warnings, as they start fresh without legacy package modifications. On systems that use SELinux or AppArmor, leaving unexpected files in system directories might trigger security warnings, though dpkg itself doesn't enforce this.

Frequently asked questions

What does "dpkg: warning: unable to delete old directory '/path': Directory not e" mean?
When dpkg removes or upgrades a package, it attempts to delete directories that were part of the old package structure. If the directory contains leftover files (especially newer files added in recent package versions), dpkg cannot delete the non-empty directory and emits this warning. This typically happens with system directories like /etc, /usr/lib, or /var that contain configuration files or plugins beyond what dpkg owns.
How do I fix "dpkg: warning: unable to delete old directory '/path': Directory not e"?
This warning appears when dpkg cannot fully delete a directory during package removal or upgrade because the directory still contains files. This is usually harmless and occurs when package maintainers add new files that older versions didn't account for. The directory can typically be manually cleaned up or left as-is since it doesn't prevent the package operation from completing.
What causes "dpkg: warning: unable to delete old directory '/path': Directory not e"?
Directory contains files that don't belong to the package being removed User-added or plugin files exist in the directory that dpkg cannot remove Third-party software has added files to system directories
Is the "dpkg: warning: unable to delete old directory '/path': Directory not e" error serious?
It is a low-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading