Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

dpkg cannot unpack a .deb and reports error processing archive

Your error

dpkg: error processing archive /var/cache/apt/archives/foo_2.0-1_amd64.deb (--unpack):3 more lines it can show

Fix it fast

Most common cause, 1 of 4

Another installed package already owns the file

If the owning package is a leftover you no longer need (often the one from the outside repository), remove it, then let apt finish the interrupted install.

Fix
sudo apt remove foo-data
sudo apt --fix-broken install
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

dpkg prints error processing archive (--unpack) when it cannot unpack a .deb, and the indented line under it gives the reason. On Ubuntu 24.04 with dpkg 1.22, look for trying to overwrite (a file another package owns), unexpected end of file or stream (a download cut short) or No space left on device (a full disk).

  • Applies to Ubuntu 24.04, dpkg 1.22, apt 2.8
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Run the failing install once more and keep only the dpkg line that names the archive plus the indented line right below it; check free space at the same time. trying to overwrite, unexpected end of file or stream and No space left on device each lead to a different cause.

Run this first
sudo apt install foo 2>&1 | grep -A1 "error processing archive"
df -h / /var

Then find the line you see in this list and open its fix:

  1. 1Another installed package already owns the filetrying to overwrite '<path>', which is also in package <other> (<version>)
  2. 2Both packages have to stay and the overlap is a packaging bugThe same trying to overwrite line, but removing the owner would also remove software you need
  3. 3The downloaded .deb in the apt cache is cut shortcannot copy extracted data for '<file>' to '<file>.dpkg-new': unexpected end of file or stream
  4. 4The disk filled up during the unpackcannot copy extracted data for '<file>' to '<file>.dpkg-new': cannot write (No space left on device)

What does the error look like?

  • dpkg: error processing archive /var/cache/apt/archives/foo_2.0-1_amd64.deb (--unpack):
  • trying to overwrite '/usr/share/foo/data.xml', which is also in package foo-data (1.0-1)
  • cannot copy extracted data for './usr/lib/foo/libfoo.so' to '/usr/lib/foo/libfoo.so.dpkg-new': unexpected end of file or stream
  • Errors were encountered while processing:

Cause 1 of 4

Another installed package already owns the file

You seetrying to overwrite '<path>', which is also in package <other> (<version>)

Check

error processing archive with trying to overwrite means the new package ships a file that dpkg already records as belonging to another package. Debian policy calls that an error unless the new package declares that it Replaces the old one; packages from different publishers, such as a PPA, a vendor repository or a .deb installed by hand, do not know about each other's files. Find the owner and where it came from.

Check
dpkg -S /usr/share/foo/data.xml
apt-cache policy foo-data

Fix

If the owning package is a leftover you no longer need (often the one from the outside repository), remove it, then let apt finish the interrupted install.

Fix
sudo apt remove foo-data
sudo apt --fix-broken install

Verify

dpkg -S now names the new package as the owner of the file, and apt reports nothing left to fix.

Verify
dpkg -S /usr/share/foo/data.xml

Confirmed by debian.org

Did this fix it?

Cause 2 of 4

Both packages have to stay and the overlap is a packaging bug

You seeThe same trying to overwrite line, but removing the owner would also remove software you need

Check

error processing archive for a file shared by two packages you must keep means the newer package lacks the Replaces field it should have, which is a bug for its maintainer. dpkg can take the file over once with the overwrite force option; its manual warns that force options are meant for experts and can break the system when used without understanding.

Fix

Unpack only the one archive with --force-overwrite, let apt complete the rest, and report the overlap to whoever publishes the newer package.

Fix
sudo dpkg -i --force-overwrite /var/cache/apt/archives/foo_2.0-1_amd64.deb
sudo apt --fix-broken install

Verify

dpkg --audit prints nothing, so no package is left half installed.

Verify
sudo dpkg --audit

Confirmed by manpages.ubuntu.com

Did this fix it?

Cause 3 of 4

The downloaded .deb in the apt cache is cut short

You seecannot copy extracted data for '<file>' to '<file>.dpkg-new': unexpected end of file or stream

Check

error processing archive with unexpected end of file or stream means dpkg ran out of data before the end of a file inside the .deb, so the copy in /var/cache/apt/archives is incomplete. dpkg's own copy routine raises exactly that message when the archive stream ends before the expected size.

Check
ls -l /var/cache/apt/archives/foo_2.0-1_amd64.deb

Fix

Clear the cached package files so apt fetches a fresh copy, then install again.

Fix
sudo apt clean
sudo apt --fix-broken install

Verify

apt downloads the package again and the unpack step completes.

Verify
sudo dpkg --audit

Confirmed by salsa.debian.org

Did this fix it?

Cause 4 of 4

The disk filled up during the unpack

You seecannot copy extracted data for '<file>' to '<file>.dpkg-new': cannot write (No space left on device)

Check

error processing archive with No space left on device means dpkg could not write the extracted file because the file system holding it is full. df shows which mount is at 100 percent; /, /usr and /var are the ones that matter for packages.

Check
df -h / /usr /var /boot

Fix

Free space first. Removing cached .deb files and packages that were only pulled in as dependencies and are no longer needed are the two apt-side steps; then retry the install.

Fix
sudo apt clean
sudo apt autoremove
sudo apt --fix-broken install

Verify

df shows free space on the mount, and apt finishes without an unpack error.

Verify
df -h / /var

Confirmed by manpages.ubuntu.com

Did this fix it?

How do I stop it coming back?

  • Before installing a vendor .deb, run dpkg -c on it and dpkg -S on a few of its paths to see whether an installed package owns them already.
  • Alert on disk use for / and /var on servers that take unattended upgrades, long before either one fills.
  • Remove PPAs and hand-installed .deb files once the Ubuntu archive carries the same software.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.