How to fix dpkg: error: unable to clean up mess surrounding file before installing: No space left on device in APT
The dpkg package manager encountered full disk space during installation cleanup. Free up disk space by removing old package caches, then retry the installation.
Quick fix
Fixes dpkg: error: unable to clean up mess surrounding file before installing: No space left on device
df -h /- Check available disk space
- Clean the APT package cache
- Remove old kernel images (if needed)
- Check and clean /boot if needed
df -h /dpkg: error: unable to clean up mess surrounding file before installing: No space left on device
What this error means
This error occurs when the APT/dpkg package manager attempts to clean up temporary installation files but runs out of storage space. The system has insufficient disk space (typically on the root partition or /var partition where APT stores cache) to complete the package installation or upgrade. This commonly happens on systems with small root partitions or after repeated kernel updates that accumulate archived .deb files.
Typical symptoms
- apt-get install or apt-get upgrade fails with dpkg cleanup error
- Package manager cannot complete any new installations
- Error occurs even after restarting the system
- Other disk-intensive operations also fail with "No space left on device"
Common causes
- APT package cache (/var/cache/apt/archives) contains too many old .deb files, consuming all available disk space
- Root filesystem is full from accumulated kernel images and old packages over time
- /boot partition is completely full from multiple kernel versions
- System has a very small root partition allocated (e.g., 20GB or less) relative to installed software
- Disk has genuinely run out of available space from user data or logs
How to fix "dpkg: error: unable to clean up mess surrounding file before installing: No space left on device"
First, determine how much space is available on your root partition:
df -h /Look for the "Use%" column. If it shows 100% or very close (95%+), you need to free space immediately. Also check:
df -h /var
du -sh /var/cache/apt/archivesThis shows how much space the APT cache is consuming.
Remove all cached .deb files (both used and unused packages):
sudo apt-get cleanThis is safe and removes all archived packages from /var/cache/apt/archives. It does not uninstall anything.
For a more aggressive clean of just unused packages:
sudo apt-get autocleanThen verify space was freed:
df -h /If cleaning the APT cache wasn't enough, remove old kernel images:
First, see which kernels are installed:
dpkg -l 'linux-*' | grep '^ii'Then remove old kernels (keep the currently running one):
uname -r # Shows your current kernel versionRemove kernels older than your current one:
sudo apt-get remove --purge linux-image-[old-version]-genericReplace [old-version] with the specific kernel version. Repeat for multiple old kernels.
Then clean again:
sudo apt-get autoclean
sudo apt-get autoremove --purgeIf /boot is the full partition, it likely contains multiple kernel images:
df -h /bootRemove old kernel files from /boot:
sudo apt-get autoremove --purge
sudo apt-get autocleanIf /boot is still full after removing kernels via apt, you may need to manually clean:
ls -lh /bootDo not manually delete files in /boot unless absolutely necessary. Prefer using apt.
Once you've freed enough space (aim for at least 500MB-1GB free), retry your package operation:
sudo apt-get install [package-name]
# or
sudo apt-get upgradeMonitor disk usage during installation:
df -h / # Check in another terminalAdvanced notes
SELinux or AppArmor may interfere with dpkg cleanup on some systems. If the issue persists after freeing space, check security policy violations with sudo journalctl -xe.
On systemd systems, journal logs can consume significant space. Clean them with:
sudo journalctl --vacuum=50M # Keep only 50MB of logsFor permanent prevention, allocate at least 50GB for the root filesystem on new installs, especially if frequent package updates are expected. Use LVM if possible to dynamically expand partitions without reinstalling.
Frequently asked questions
- What does "dpkg: error: unable to clean up mess surrounding file before installin" mean?
- This error occurs when the APT/dpkg package manager attempts to clean up temporary installation files but runs out of storage space. The system has insufficient disk space (typically on the root partition or /var partition where APT stores cache) to complete the package installation or upgrade. deb files.
- How do I fix "dpkg: error: unable to clean up mess surrounding file before installin"?
- The dpkg package manager encountered full disk space during installation cleanup. Free up disk space by removing old package caches, then retry the installation.
- What causes "dpkg: error: unable to clean up mess surrounding file before installin"?
- APT package cache (/var/cache/apt/archives) contains too many old .deb files, consuming all available disk space Root filesystem is full from accumulated kernel images and old packages over time /boot partition is completely full from multiple kernel versions
- Is the "dpkg: error: unable to clean up mess surrounding file before installin" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.