How to Solve “Sub-process /usr/bin/dpkg returned an error code (1)” In Ubuntu

[‘

n

It’s not uncommon to run into an issue of broken packages in Ubuntu and other Debian-based distributions. Sometimes, when you upgrade the system or install a software package, you may encounter the ‘Sub-process /usr/bin/dpkg returned an error code’ error.

n

For example, a while back, I tried to upgrade Ubuntu 18.04 and I bumped into the dpkg error as shown below.

n

Errors were encountered while processing:rngoogle-chrome-stablernE: Sub-process /usr/bin/dpkg returned an error code (1)rn

n

This indicates that the google-chrome-stable package is either broken or corrupt. There are a few workarounds to this problem, so don’t throw in the towel yet or discard your system.

n

Solution 1: Reconfiguring the dpkg Package

n

One of the triggers of this error is a corrupted dpkg database. This can be caused by the sudden interruption of the installation of a software package. Reconfiguring the database is one way to resolve this issue.

n

To do this, simply execute the command:

n

$ sudo dpkg --configure -arn

n

This reconfigures the unpacked packages that were not installed during the installation process.

n

Solution 2: Force Install the Troublesome Package

n

Sometimes, errors can occur during the installation of software packages. When such happens, you can force install the package using the -f option as shown.

n

$ sudo apt install -frnORrn$ sudo apt install --fix-brokenrn

n

The -f option & --fix-broken can be interchangeably used to fix broken dependencies resulting from an interrupted package or cached package download.

n

Solution 3: Purge the Bad or Corrupted Software Package

n

If the first two solutions did not fix the problem, you can remove or purge the problematic software package as shown.

n

$ sudo apt remove --purge package_namern

n

For example, in my case, purging the Google chrome package fixed the issue.

n

$ sudo apt remove --purge google-chrome-stablern

n

Then invoke the commands below to remove all the old, unused, and unnecessary packages which also frees up space on your hard drive.

n

$ sudo apt cleanrn$ sudo apt autoremovern

n

Solution 4: Remove all the Files Associated with the Package

n

Lastly, you can manually remove all the associated with the troublesome package. First, you need to find these files which are located in the /var/lib/dpkg/info directory as shown.

n

$ sudo ls -l /var/lib/dpkg/info | grep -i package_namern

n

After listing the files, you can move them to the /tmp directory as shown

n

$ sudo mv /var/lib/dpkg/info/package-name.* /tmprn

n

Alternatively, you can use the rm command to manually remove the files.

n

$ sudo rm -r /var/lib/dpkg/info/package-name.*rn

n

Finally, update the package lists as shown:

n

$ sudo apt updatern

n

You can thereafter give it another shot in reinstalling the software package.

n

Conclusion

n

This type of dpkg error points to an issue with the package installer usually caused by the interruption of an installation process or a corrupt dpkg database.

n

Any of the above-mentioned solutions should fix this error. If you have come this far, then it’s our hope that the issue has been successfully resolved and that you were able to reinstall your software package.

n

‘]