Ubuntu – E: Sub-process /usr/bin/dpkg returned an error code (1) – but how to find the meaningful error messages in APT’s output


I have encountered various package management problems that cause APT commands to fail with output that ends with this line:

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

Occasionally other error codes may appear such as 100 which means dpkg is not there, but 1 is the most common error code.

Unfortunately this error code tells me almost nothing about what actually caused the error or how I should solve it. Almost every package management issue I see, regardless of its cause or solution, produces the same error!

So, where will I find the useful part of the output, which I can search for online or ask questions about on Ask Ubuntu?

Best Answer

Apt logs it's actions sequentially, just like a human does.

Simply read the output line-by-line.

Here is a non-apt example. Read it line-by-line and you will see that it tells a story:

I am going to build a tower out of five blocks...
Clearing a working surface in the kitchen.
Kitchen: Put 7 dirty dishes from the counter into the dishwasher
Kitchen: Wiped the counter clean
Opening the box of blocks.
Warning: There are only three blocks in the box.
Build: Placed the first block.
Build: Placed the second block.
Build: Placed the third block.
Build: ERROR: Cannot keep building - ran out of blocks.
Closing the box of blocks.
ERROR (summary): Failed to complete the five-block tower.

Apt and dpkg logging works in exactly the same way - you read the story line-by-line. You see the package manager embark upon it's adventure: prepare, run subtasks, encounter non-fatal problems (Warnings), overcome adversity, etc.

Most of the output is routine, but you need it to mark apt's progress. That context is how you understand what was happening. It really is a story.

Error (1) is common. It's a summary error code, indicating that the problem occurred to a subtask ("some problem building"). Jump backward in the story to where that particular subtask occurred, and you will see the specific detail ("ran out of blocks").

Related Question