Ubuntu error: Sub-process /usr/bin/dpkg returned an error code (1)


Example error:

root@tutorialspots:~# sudo apt-get install -y mongodb-database-tools mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
mongodb-org is already the newest version (5.0.8).
The following packages were automatically installed and are no longer required:
  libboost-filesystem1.71.0 libboost-iostreams1.71.0
  libboost-program-options1.71.0 libgoogle-perftools4 libtcmalloc-minimal4
  libyaml-cpp0.6 mongo-tools
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  mongodb-database-tools
0 upgraded, 1 newly installed, 0 to remove and 64 not upgraded.
8 not fully installed or removed.
Need to get 0 B/46.5 MB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 52439 files and directories currently installed.)
Preparing to unpack .../mongodb-database-tools_100.5.2_amd64.deb ...
Unpacking mongodb-database-tools (100.5.2) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-database-tools_100.5.2_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/bsondump', which is also in package mongo-tools 3.6.3-0ubuntu1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/mongodb-database-tools_100.5.2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

We see the main reason is trying to overwrite '/usr/bin/bsondump', which is also in package mongo-tools 3.6.3-0ubuntu1

Caused package: mongo-tools

Solution:

Step 1: find files to remove: sudo ls -l /var/lib/dpkg/info | grep -i package_name

Result:

root@tutorialspots:~# sudo ls -l /var/lib/dpkg/info | grep -i mongo-tools
-rw-r--r-- 1 root root     727 Apr 12 13:53 mongo-tools.list
-rw-r--r-- 1 root root    1315 Apr 10  2018 mongo-tools.md5sums

Step 2: move or delete thoses files: sudo mv /var/lib/dpkg/info/package_name.* /tmp

Example: sudo mv /var/lib/dpkg/info/mongo-tools.* /tmp

Step 3: update the package manager: sudo apt-get update

Done!

Leave a Reply