Skip to content

Instantly share code, notes, and snippets.

@samba
Last active January 20, 2025 21:16
Show Gist options
  • Save samba/f5a806d233b2ba464c6d3a91e23ec1d9 to your computer and use it in GitHub Desktop.
Save samba/f5a806d233b2ba464c6d3a91e23ec1d9 to your computer and use it in GitHub Desktop.
Arch Linux package cleaning

Cleaning installed packages on Arch Linux

Removing specific unneeded packages.

I find that many apps use different versions of Electron, and I'm left with residual Electron versions no longer used.

sudo pacman -Qqtd | grep electron | sudo pacman -Rs -

Sometimes this is useful for removing a source-build package and replacing it with a prebuilt binary package, e.g. for Qt libraries.

Remove all orphaned packages.

Caution this is hazardous. You should directly review all packages before removing them, to ensure you're not removing critical dependencies.

Review all packages who were once installed as dependencies but no longer required by another package.

sudo pacman -Qqtd | less

Before removing all orphaned packages (below), do check that you're not removing a critical build dependency (e.g. cmake) that will prevent you from building and installing packages you need.

sudo pacman -Qqtd | sudo pacman -Rs -

Finding package dependents.

You can determine which other packages would be affected by removal of a package as well.

for i in electron electron31 electron27 ; do sudo pacman -Sii ${i} ; done | less

Perhaps easier is to find only the impacted packages from a set:

sudo pacman -Qqtd | grep electron | sudo pacman -Sii - | grep "Required By"

Check all installed packages for missing dependencies.

Find all packages on the system who have some missing dependencies.

sudo pacman -Qq | sudo xargs -L 1 pacman -T | less

You can resolve their dependencies by reinstalling the affected packages.

Cleaning cache

You may be retaining several gigabytes of older package versions in your local cache. Sometimes cleaning that is helpful.

sudo pacman -Sc

Pacman will also clean the cache automatically after every upgrade if you want...

sudo pacman -Syuc

Removing packages and their dependencies

Ideally you'd remove backages you no longer need, and let Pacman prune orphaned packages at the same time, as well as all packages that depend on whatever you specifically removed.

Caution is warranted, as you'd best review the removed packages to avoid removing something you needed by accident.

sudo pacman -Rcsu _packagename_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment