Update or package installation returns “error: failed to commit transaction (invalid or corrupted package)”

I can’t install or update a package because I get (something like) this:

error: failed to commit transaction (invalid or corrupted package)

Errors occurred, no packages were upgraded.

Why is this happening?

The package manager, pacman , has detected a malformed or incomplete package. By design it will not install the broken package. This is a design feature, not a flaw - you dont want to install corrupted files.

This issue normally happens because the process was interrupted (for example losing internet during download). In rarer cases it could stem from the mirror in use or the uploaded file it has on hand.

How can I fix this?

The easiest way

If it is just an issue of some partial downloads then they will usually be marked with file extension
To easily find and remove such files you can run:

find /var/cache/pacman/pkg/ -iname "*.part" -exec sudo rm {} \;

The more involved way

If you can manage to pinpoint which package is at fault you can manually remove it from the cache.

sudo rm /var/cache/pacman/pkg/sddm-breath2-theme-1.0.4-1-any.pkg.tar.zst

The stronger way

Sometimes the package in question is not marked with a .part but is corrupted nonetheless.
Other times a particular mirror may be having problems.

To sort mirrors:

sudo pacman-mirrors -f && sudo pacman -Syyu

If changing mirrors does not help and you cannot identify the problematic package, then you may opt to clear the entire cache. This is not necessarily desirable because you will no longer have access to them, but you may have no other choice. One tool to accomplish this is paccache :

paccache -rvk0

Then attempt the update or installation again.

Related: “No such file or directory”, “FILENAME exists in filesystem”

If you have either of these errors please see this guide: