How to fix dpkg: error: unable to clean up mess surrounding file before installing: No space left on device in APT

APTINTERMEDIATEHIGHUpdated Dec 29, 2025· 206 views

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 /
  1. Check available disk space
  2. Clean the APT package cache
  3. Remove old kernel images (if needed)
  4. Check and clean /boot if needed
apt — error
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

  1. APT package cache (/var/cache/apt/archives) contains too many old .deb files, consuming all available disk space
  2. Root filesystem is full from accumulated kernel images and old packages over time
  3. /boot partition is completely full from multiple kernel versions
  4. System has a very small root partition allocated (e.g., 20GB or less) relative to installed software
  5. 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"

1Check available disk space

First, determine how much space is available on your root partition:

bash
df -h /

Look for the "Use%" column. If it shows 100% or very close (95%+), you need to free space immediately. Also check:

bash
df -h /var
du -sh /var/cache/apt/archives

This shows how much space the APT cache is consuming.

2Clean the APT package cache

Remove all cached .deb files (both used and unused packages):

bash
sudo apt-get clean

This 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:

bash
sudo apt-get autoclean

Then verify space was freed:

bash
df -h /
3Remove old kernel images (if needed)

If cleaning the APT cache wasn't enough, remove old kernel images:

First, see which kernels are installed:

bash
dpkg -l 'linux-*' | grep '^ii'

Then remove old kernels (keep the currently running one):

bash
uname -r  # Shows your current kernel version

Remove kernels older than your current one:

bash
sudo apt-get remove --purge linux-image-[old-version]-generic

Replace [old-version] with the specific kernel version. Repeat for multiple old kernels.

Then clean again:

bash
sudo apt-get autoclean
sudo apt-get autoremove --purge
4Check and clean /boot if needed

If /boot is the full partition, it likely contains multiple kernel images:

bash
df -h /boot

Remove old kernel files from /boot:

bash
sudo apt-get autoremove --purge
sudo apt-get autoclean

If /boot is still full after removing kernels via apt, you may need to manually clean:

bash
ls -lh /boot

Do not manually delete files in /boot unless absolutely necessary. Prefer using apt.

5Retry your installation

Once you've freed enough space (aim for at least 500MB-1GB free), retry your package operation:

bash
sudo apt-get install [package-name]
# or
sudo apt-get upgrade

Monitor disk usage during installation:

bash
df -h /  # Check in another terminal

Advanced 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:

bash
sudo journalctl --vacuum=50M  # Keep only 50MB of logs

For 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.

Official resources & further reading