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

In this MongoDB tutorial, I will explain how I managed to resolve the error “E: Sub-process /usr/bin/dpkg returned an error code (1)”.

  • Sub-process /usr/bin/dpkg returned an error code (1)
  • Reason: Sub-process /usr/bin/dpkg returned an error code (1)
  • Solution: Sub-process /usr/bin/dpkg returned an error code (1)
  • Conclusion

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

Recently, when I was trying to install the MongoDB database in the ubuntu operating system (20.04), I faced the error “Sub-process /usr/bin/dpkg returned an error code (1)“. You can see the error below:

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

I properly followed the correct command, but still faced this error.

Don’t worry if you don’t know how to resolve these issues. In the below steps, we will discuss the reason for getting the error and also resolve the error.

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

When I searched it on the web, I found many posts and blogs on this error. Most of the blogs stated that this error was triggered because of a failed software installation or the installer becomes corrupted.

So if it is damaged and you are trying any new software installation will cause this error message.

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

When I was trying to troubleshoot this error in the Ubuntu operating system. I found the solution for this.

The installer becomes corrupted that is the only reason we are getting errors. The key phrase in the error is /usr/bin/dpkg. Here, the dpkg is the package installer for Linux and it tracks software updates and dependencies.

Now, follow the below steps to fix the error dpkg returned an error code 1:

  • Open the terminal
  • Use the below code to move the dpkg info file into another file
sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_silent

Here, we moved the info file into the info_silent file on the same path “/var/lib/dpkg/info_silent”. You can take any name for the new file (info_silent).

  • Now create a new directory info in dpkg folder, use the below command
sudo mkdir /var/lib/dpkg/info
  • Excute the update command to download package information from all configured sources
sudo apt-get update
dpkg returned an error code
Move directory and update packages
  • Excute the below command to check the dependencies of the packages you want and install any that are needed.
sudo apt-get -f install

Here, this command will install the MongoDB database and also check the dependencies that are needed to install.

Solution dpkg returned an error code (1)
Install MongoDB database
  • After installing all the dependencies move all the file of the info directory into info_silent directory.
sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_silent
  • Remove the info directory, use the below command
sudo rm -rf /var/lib/dpkg/info
  • Now, again move all the file of the info_silent directory into the info directory.
sudo mv /var/lib/dpkg/info_silent /var/lib/dpkg/info
  • Use the below code to updates the list of available packages and their versions
sudo apt-get update
  • After updating the lists, the package manager knows about available updates for the software you have installed.
  • Use the upgrade command to installs newer versions of the packages you have.
sudo apt-get upgrade
Solution Sub-process dpkg returned an error code (1)
Some required changes in the dpkg directory
also, update and upgrade
  • Now we resolved the error and successfully installed the MongoDB without any error fall.
  • Check the version of MongoDB, use the below command
mongod --version
MongoDB dpkg returned an error code (1)
Installed MongoDB version v5.0.3

Conclusion

The “sub-process /usr/bin/dpkg returned an error code (1)” indicates that there is a problem with the package installer, which is generally caused by an interrupted installation process or a corrupted database.

You may also like to read the following MongoDB tutorials.

Thus, you might have learned the cause and the solution of the error Sub-process /usr/bin/dpkg returned an error code (1).

  • Sub-process /usr/bin/dpkg returned an error code (1)
  • Reason: Sub-process /usr/bin/dpkg returned an error code (1)
  • Solution: Sub-process /usr/bin/dpkg returned an error code (1)
  • Conclusion

Leave a Comment