Using `pacman` to Repair a Broken Arch Linux Installation
Today, I learned a valuable command that can be a lifesaver when dealing with a broken Arch Linux installation. If you’ve ever found yourself in a situation where pacman
fails to run due to a package upgrade issue, you might appreciate the utility of the following command:
1sudo pacman --root=/mnt/arch --cachedir=/mnt/arch/var/cache/pacman/pkg -S <package>
What Went Wrong?
During a routine package upgrade, the icu
package was accidentally left behind (my own fault) due to conflicting dependencies with some AUR packages. This left the system in a state where pacman
would no longer run, effectively locking me out of my system’s package management and preventing me from rectifying the issue.
To resolve this, I booted from a live Arch Linux image, which allowed me to access my system’s files and perform the necessary repairs to get pacman
working again.
The Fix
Using the working pacman
instance on the live image, I specified a custom root
and cachedir
pointing to the mounted main installation.
1sudo pacman --root=/mnt/arch --cachedir=/mnt/arch/var/cache/pacman/pkg -Rncsd <AUR packages with conflicts>
2sudo pacman --root=/mnt/arch --cachedir=/mnt/arch/var/cache/pacman/pkg -S icu <plus any dependent packages>
This command allowed me to reinstall the icu
package directly onto the mounted system, bypassing the broken pacman
instance on the main installation. Once the package was successfully reinstalled, I was able to unmount the partition, reboot into my main Arch Linux system, and proceed to repair and reinstall the AUR packages that had conflicts.