Today I tried to upgrade my Ubuntu 20.04 LTS desktop and I encountered with this error - "Sub-process /usr/bin/dpkg returned an error code (1)". It is one of the common issue in Ubuntu and other DEB-based systems. This usually happens due to a failed application installation, or if the dpkg package installer becomes corrupted or interrupted in mid-way while installing a package.
Here are the commands I tried to upgrade my Ubuntu desktop:
$ sudo apt update
$ sudo apt upgrade
And... here is the sample error message:
Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages will be upgraded: eog 1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 21 not fully installed or removed. Need to get 0 B/421 kB of archives. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] (Reading database ... 230012 files and directories currently installed.) Preparing to unpack .../eog_3.36.2-0ubuntu1_amd64.deb ... Unpacking eog (3.36.2-0ubuntu1) over (3.36.1-1) ... dpkg-deb (subprocess): decompressing archive member: lzma error: compressed data is corrupt dpkg-deb: error: <decompress> subprocess returned error exit status 2 dpkg: error processing archive /var/cache/apt/archives/eog_3.36.2-0ubuntu1_amd64.deb (--unpack): cannot copy extracted data for './usr/lib/x86_64-linux-gnu/eog/libeog.so' to '/usr/lib/x86_64-linux-gnu/eog/libeog.so.dpkg-new': unexpected end of file or stream Errors were encountered while processing: /var/cache/apt/archives/eog_3.36.2-0ubuntu1_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)
Fix "Sub-process /usr/bin/dpkg returned an error code (1)" In Ubuntu
If you encountered with an error like above, worry not! Here, I have given a few workarounds to solve "Sub-process /usr/bin/dpkg returned an error code (1)" issue in Ubuntu and its variants such as Linux Mint, Pop OS.
Solution 1 - Reconfigure dpkg database
If the package installation process is stopped or interrupted in mid-way, the dpkg database might be corrupted. Reconfiguring dpkg database may solve this issue.
To reconfigure dpkg database, simply run:
$ sudo dpkg --configure -a
This command will try to fix the corrupted dpkg database and then reconfigure all broken packages. This command usually fixes the dpkg returned an error code (1) problem. If it is not solved for any reason, follow the subsequent solutions.
Solution 2 - Force install the application
If the first method didn't work, run the following command to perform force install:
$ sudo apt-get install -f
$ sudo apt-get install --fix-broken
Here, -f (or --fix-broken) option will attempt to correct the Ubuntu system with broken dependencies.
If these two solutions didn't help and the issue still persists, try the next solution.
Solution 3 - Remove the problematic application .deb file from the local cache folder and reinstall it
As you see in the error message (the last two lines), the eog package is causing this error.
[...] /var/cache/apt/archives/eog_3.36.2-0ubuntu1_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)
For those wondering, eog (short for Eye of GNOME) is the official and default image viewer for the GNOME desktop environment. So this package is problematic and doesn't let me to upgrade my Ubuntu.
When you install a package, it will be downloaded and saved in the cache folder /var/cache/apt/archives/.
To fix this error, remove the cached package using command:
$ sudo rm /var/cache/apt/archives/eog_3.36.2-0ubuntu1_amd64.deb
Replace eog_3.36.2-0ubuntu1_amd64.deb with your package.
Clean the package cache folder:
$ sudo apt-get clean
$ sudo apt-get autoremove
Update the source lists:
$ sudo apt-get update
Upgrade your system:
$ sudo apt-get upgrade
Finally, get the fresh package from official repositories and reinstall it like below:
$ sudo apt-get install eog
This solution worked for me.
Solution 4 - Remove the problematic application
This should be your last resort. If none of the above methods help, remove the problematic package from your system like below:
$ sudo apt-get remove --purge eog
$ sudo apt-get clean && sudo apt-get autoremove
This command will remove eog with all its configuration files from the system.
And also find and remove all files associated with the broken package.
To find all files related to a package, run:
$ sudo ls -l /var/lib/dpkg/info | grep -i eog
-rw-r--r-- 1 root root 61926 Apr 24 13:42 eog.list -rw-r--r-- 1 root root 5889 Mar 29 08:01 eog.md5sums
Remove them manually.
That's it. At this stage, any one of the these four solutions should have helped you to fix "Sub-process /usr/bin/dpkg returned an error code (1)" in Ubuntu and other DEB-based systems.
If your Ubuntu system is completely broken and you can't log into it anymore, refer the following guide to get it fixed.