"Error processing package" - apt upgrade cannot run due to package configuration errors

Solution 1:

With

stat / /dev /var

check if you are the owner of all directories. If not, run:

chown root DirectoryYouAreNotOwner

In my case, the owner of / was Unknown. So I used the command:

chown root /

Solution 2:

The answer of Miguel Saldanha did not work for me and I tried searching a bit more. Finally, the answer from this post helped me. Just posting the answer here because this has been referred in several places and in case someone needs it in future.

sudo rm /var/lib/dpkg/info/systemd*
sudo dpkg --configure -D 777 systemd
sudo apt -f install

Hope it helps.