Help! Accidently ran 'sudo rm -f /var/lib/pacman/local/*/desc' and am now unable to use pacman

Hello!

I was attempting to migrate to CachyOS repos, and while googling how to fix an issue, I ran a command I found without thinking, which was:

sudo rm -f /var/lib/pacman/local/*/desc

Now, when I attempt to use pacman, I get errors like these:
error: could not open file /var/lib/pacman/local/xfwm4-themes-4.10.0-6/desc: No such file or directory
error: could not open file /var/lib/pacman/local/yt-x-git-v0.4.5.r62.gba700d7-1/desc: No such file or directory
looking for conflicting packages…
error: could not open file /var/lib/pacman/local/a52dec-0.8.0-3/desc: No such file or directory
warning: could not fully load metadata for package a52dec-0.8.0-3
error: failed to prepare transaction (invalid or corrupted package)

For context, it says desc is missing for every single package on the system.

So far I’ve tried:

Before I try anything further, especially as I’m unclear on the fragility of the situation, I thought I’d ask for help.

If it’s of any use:

  • I do have a USB on hand if arch-chroot is needed
  • I am happy to provide any system logs

Hi @Crosszay , welcome to the forum! :confetti_ball:

That command deleted the desc file for every installed package — pacman uses those to track what’s installed, so the local database is now incomplete.

The likely fix is reinstalling all packages from the repos, which regenerates the missing desc files:

sudo pacman -Qnq | sudo pacman -S --overwrite "*" -

This is safe to run. But before trying, can you share the output of:

ls /var/lib/pacman/local/xfwm4-themes-4.10.0-6/
ls /var/cache/pacman/pkg/ | head -20

That tells us if the wiki restore procedure did anything useful, and whether the fix above is likely to work.

Welcome to the community @Crosszay! :waving_hand::smiley: :enos_flag:

In my tests, pacman will not proceed so long as the desc file is missing. For example, I remove /var/lib/pacman/local/xz-5.8.3-1/desc, then I try to re-install xz:

sudo pacman -S --overwrite "*" xz

It throws:

warning: xz-5.8.3-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...
error: could not open file /var/lib/pacman/local/xz-5.8.3-1/desc: No such file or directory
warning: could not fully load metadata for package xz-5.8.3-1
error: failed to prepare transaction (invalid or corrupted package)

The good news is however, it will succeed, so long as a desc file is present. It doesn’t need anything in it, an empty file will suffice. So using the output you’ve shared so far @Crosszay, that’d be something like:

sudo touch /var/lib/pacman/local/xfwm4-themes-4.10.0-6/desc
sudo touch /var/lib/pacman/local/yt-x-git-v0.4.5.r62.gba700d7-1/desc
sudo touch /var/lib/pacman/local/a52dec-0.8.0-3/desc

Re-installing those packages should then correct the contents of desc.

That doesn’t sound like an “accidental” occurrence :sweat_smile:

I would rather say “mistakenly”, “against my better judgement” or “inadvertently”.

Luckily, the suggestion proposed by @Bink will save you the day.

There is too much intention involved in googling stuff, copying command lines you don’t understand the consequences and implications of, putting it in your terminal and pressing enter.

So please be mindful of what you find online next time when you are trying to solve an issue and if you don’t fully understand the “solutions” you find, post it here and ask so you won’t have similar accidents in the future.

Remember, having sudo is a great responsibility and that responsibility is only on your shoulder.

Hi!

Maybe this command:

sudo pacman -Sy --overwrite "*" xz

to force pacman getting the latest package version? Not sure I’m right about this btw
(On CachyOS, I sometimes have to do this for some packages installations as the version changed and I’d got errors that the file where not available. Maybe your error could be the same)

Otherwise, these commands “may” help (but please, wait for better users than me that can give you a GO to test, especially the second command):
sudo pacman -Syu
This command refreshes the package database if it is out of date and upgrades all installed packages to their latest available versions. This is the recommended command for routine system maintenance, as it ensures compatibility between packages by upgrading everything simultaneously.

sudo pacman -Syuu
This command enables downgrade packages. Pacman will install newer versions of packages if they exist, but if the repository contains an older version than what is currently installed locally, it will downgrade the package to match the repository. This is typically used only in specific scenarios, such as switching from a testing repository to a stable one, or when trying to fix issues caused by a new package version being removed or rolled back.

Best Regards,

V.

$ sudo pacman -Sy --overwrite "*" xz
:: Synchronizing package databases...
 endeavouros is up to date
 core is up to date
 extra                                                              8.2 MiB  17.5 MiB/s 00:00 [-------------------------------------------------------] 100%
 multilib is up to date
warning: xz-5.8.3-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...
error: could not open file /var/lib/pacman/local/xz-5.8.3-1/desc: No such file or directory
warning: could not fully load metadata for package xz-5.8.3-1
error: failed to prepare transaction (invalid or corrupted package)

Unfortunately, no dice on that one :wink:

But thanks for the suggestion and thoughts, all the same.

Try something like this for each affected package (here just xz):

# sudo rm /var/lib/pacman/local/xz-*/desc   # simulates the problem with xz
# then fix xz:
sudo pacman -Rdd xz
sudo pacman -Sy --overwrite '*' xz

I think this will not preserve dependencies though…
But @Bink 's suggestion to create the missing desc file by touching should work better:

sudo touch /var/lib/pacman/local/xz-*/desc
sudo pacman -S --overwrite '*' xz

Thanks for your help!

The output of:

ls /var/lib/pacman/local/xfwm4-themes-4.10.0-6/

is:

files mtree
and the output of:

ls /var/cache/pacman/pkg/ | head -20

is:

a52dec-0.8.0-3-x86_64.pkg.tar.zst
a52dec-0.8.0-3-x86_64.pkg.tar.zst.sig
aalib-1.4rc5-19-x86_64.pkg.tar.zst
aalib-1.4rc5-19-x86_64.pkg.tar.zst.sig
abseil-cpp-20260107.1-1-x86_64.pkg.tar.zst
abseil-cpp-20260107.1-1-x86_64.pkg.tar.zst.sig
accountsservice-26.13.3-1-x86_64.pkg.tar.zst
accountsservice-26.13.3-1-x86_64.pkg.tar.zst.sig
acl-2.3.2-2-x86_64.pkg.tar.zst
acl-2.3.2-2-x86_64.pkg.tar.zst.sig
adwaita-cursors-50.0-1-any.pkg.tar.zst
adwaita-cursors-50.0-1-any.pkg.tar.zst.sig
adwaita-fonts-50.0-1-any.pkg.tar.zst
adwaita-fonts-50.0-1-any.pkg.tar.zst.sig
adwaita-icon-theme-50.0-1-any.pkg.tar.zst
adwaita-icon-theme-50.0-1-any.pkg.tar.zst.sig
adwaita-icon-theme-legacy-46.2-3-any.pkg.tar.zst
adwaita-icon-theme-legacy-46.2-3-any.pkg.tar.zst.sig
alacritty-0.17.0-1-x86_64.pkg.tar.zst
alacritty-0.17.0-1-x86_64.pkg.tar.zst.sig

Thanks for your help!

The issue is on every package, so I assume I should run something like:

sudo touch /var/lib/pacman/local/*/desc?

Mistakenly might be the better term here. I had been dealing with an issue with installing a certain package for a bit, and in my frustration, pasted in that command. I didn’t look at it too hard, which was entirely my fault, assuming it was something related to pacman’s cache or something; obviously this was not the case, and in hindsight, there was no reason for me to think that.

Your package cache is well populated, so the fix should work cleanly.

sudo pacman -Qnq | sudo pacman -S --overwrite "*" -

This will take a while depending on the packages.

Appreciate your help! Unfortunately, these two commands were some of the first things I tried (Apologies for not listing them in the original message), and they did not fix anything.

Appreciate the quick reply!

sudo pacman -Qnq | sudo pacman -S --overwrite "*" -

Unfortunately does not suceed, and instead returns:

error: could not open file /var/lib/pacman/local/yt-x-git-v0.4.5.r62.gba700d7-1/desc: No such file or directory
looking for conflicting packages…
error: could not open file /var/lib/pacman/local/a52dec-0.8.0-3/desc: No such file or directory
warning: could not fully load metadata for package a52dec-0.8.0-3
error: failed to prepare transaction (invalid or corrupted package)

I’ve truncated the output for readability, but the system does complain about a missing desc for each and every package installed.


The error makes sense — pacman tries to read every desc before it can do anything, so it trips over itself immediately. Sorry for that.

Next try for recovery is to boot your USB, chroot in, and run:

pacman -Sy
pacman -Slq > /tmp/repo_pkgs.txt
ls /var/lib/pacman/local/ | grep -v ALPM_DB_VERSION | sed 's/-[^-]*-[^-]*$//' > /tmp/installed.txt
grep -xF -f /tmp/installed.txt /tmp/repo_pkgs.txt > /tmp/to_reinstall.txt
pacman --noscriptlet --dbonly --overwrite "*" --nodeps -S - < /tmp/to_reinstall.txt

What it does.

  • line 1 — syncs the repo databases so pacman knows what’s available
  • line 2 — dumps a list of every package in the repos to a file
  • line 3 — lists what’s installed on your system (strips version numbers off the directory names)
  • line 4 — cross-references the two lists, keeping only packages that exist in the repos
  • line 5 — reinstalls just the database entries, without touching any actual files or running install scripts

AUR packages won’t be covered, but they’ll just show warnings.

Good luck…

Use the following command to create an empty desc file in all the subdirectories of /var/lib/pacman/local

sudo find /var/lib/pacman/local -mindepth 1 -maxdepth 1 -type d -exec touch '{}/desc' \;

Then try reinstalling all your packages:

Yeah, if only re-creating those worked the same way as removing them :sweat_smile:

Give @cactux’s suggestion a go :wink:

This was the solution!

Thank you for your help everyone! Espescially @Bink and @cactux !

@cactux :smiling_face_with_sunglasses: :right_facing_fist: :left_facing_fist: :smiling_face_with_sunglasses:

high-five

Glad you could sort it out!
Credit should go to @Bink :smiling_face_with_sunglasses: :right_facing_fist: :left_facing_fist: :smiling_face_with_sunglasses: for hinting at the creation of empty desc files and re-installation of the packages.