LLI Wiki — My Digital Knowledge Base

pacman and yay cheat sheet with apt/dnf/zypper/emerge equivalents

Everyday pacman and yay commands on Arch Linux, equivalents in other package managers, and RPM troubleshooting.

This cheat sheet covers day-to-day package management on Arch Linux with pacman (and the AUR helper yay), a short equivalence table with other distributions, and a few RPM-based troubleshooting commands for Red Hat systems.

Updating the system

sudo pacman -Syu     # refresh databases and upgrade the whole system
sudo pacman -Syy     # force a refresh of the package databases

Installing and removing packages

sudo pacman -S package_name            # install from the repositories
sudo pacman -U /path/to/package.pkg.tar.zst   # install a local package file
sudo pacman -R package_name            # remove the package only
sudo pacman -Rs package_name           # remove it and its unneeded dependencies
sudo pacman -Rns package_name          # also remove its global configuration (usually the right choice)
sudo pacman -Rc package_name           # remove it and every package that depends on it
sudo pacman -Rdd package_name          # remove it ignoring dependencies (use -d twice)

Reinstall all repository packages in an emergency (excluding foreign/AUR packages):

sudo pacman -Sy $(pacman -Q | cut -d " " -f1 | grep -v "$(pacman -Qm | cut -d " " -f1)")

Searching and querying

pacman -Qi package_name      # info about an installed package
pacman -Ss package_name      # search the repositories
pacman -Sii package_name     # repository info, including reverse dependencies
pacman -Qm                   # foreign packages (built locally or no longer in the repositories)
pacman -Qqm                  # same, names only (AUR packages)
pacman -Qdtq                 # orphaned dependencies
pacman -Qkk | grep -v '0 altered files'   # detect altered or corrupted package files

Find which package owns a file:

sudo pacman -Fy              # update the file database first
pacman -Fs filename          # search remote packages for a file
pacman -Qo /path/to/file     # owner of an installed file

List packages by category:

# Explicitly installed packages that are not in the base groups
pacman -Qei | awk '/^Name/ { name=$3 } /^Groups/ { if ( $3 != "base" && $3 != "base-devel" ) { print name } }'

# Installed packages sorted by size
pacman -Qi | awk '/^Name/{name=$3} /^Installed Size/{print $4$5, name}' | sort -h

# Packages installed from a given repository (paclist is part of pacman-contrib)
paclist community
awk '{print $1}' <(paclist community)   # names only

Optional dependencies of a package, installed as dependencies afterwards:

pacman -Qi vlc | grep -A 64 'Optional Deps'
sudo pacman -S --asdeps optional_package

/var/log/pacman.log shows what changed.

Removing unused packages

sudo pacman -Rsn $(pacman -Qdtq)    # remove orphans
pacman -Qdtq | sudo pacman -Rs -    # equivalent form
yay -Rcns package_name              # remove an AUR package with its dependencies
yay -Yc                             # remove unneeded dependencies
yay -Ps                             # yay statistics

Cleaning the cache

ls /var/cache/pacman/pkg/ | wc -l
du -sh /var/cache/pacman/pkg/
sudo paccache -r                    # keep the last 3 versions of each package
sudo pacman -Scc                    # remove everything (interactive)
yay -Scc                            # yay cache

Run paccache automatically every week:

sudo systemctl enable paccache.timer --now

Downgrading a package

Reinstall an older version from the local cache, or from the Arch Linux Archive:

sudo pacman -U /var/cache/pacman/pkg/package-old_version.pkg.tar.zst

See the ArchWiki page Downgrading packages.

Choosing fast mirrors

Back up the current list, then generate a ranked one with rankmirrors (from pacman-contrib):

sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup

curl -s "https://archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https&ip_version=4&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 10 -

The mirror list generator also accepts one or several country=XX parameters. See the Arch mirror list generator and the Mirrors page.

Troubleshooting

Look for failed services and error-level journal entries of the current boot:

sudo systemctl --failed
sudo journalctl -p 3 -xb

Reset the pacman keyring when signature or GPG errors occur:

rm -r /etc/pacman.d/gnupg && pacman-key --init && pacman-key --populate archlinux && pacman-key --refresh-keys

If pacman itself is broken, download the needed packages (openssl, libarchive and pacman) manually, extract them, then reinstall them with pacman so the package database stays consistent:

sudo tar -xvpf package_name-version.tar.xz -C / --exclude .PKGINFO --exclude .INSTALL

See the pacman page of the ArchWiki.

Backing up the system with rsync

sudo rsync -aAXvP --delete --exclude=/dev/* --exclude=/proc/* --exclude=/sys/* --exclude=/tmp/* --exclude=/run/* --exclude=/mnt/* --exclude=/media/* --exclude=/lost+found / /mnt/backupDestination/

--delete removes files from the destination that no longer exist on the source: check the destination path before running it.

Equivalent commands across distributions

A condensed subset of the ArchWiki Pacman/Rosetta comparison.

Action Arch Red Hat / Fedora Debian / Ubuntu SLES / openSUSE Gentoo
Install pacman -S dnf install apt install zypper install emerge
Remove pacman -Rs dnf remove apt remove zypper remove emerge -vc
Search pacman -Ss dnf search apt search zypper search emerge -S
Upgrade pacman -Syu dnf upgrade apt update then apt upgrade zypper update emerge -uDN @world
Clean caches pacman -Sc / -Scc dnf clean all apt clean / autoclean zypper clean eclean distfiles
Remove unneeded dependencies pacman -Qdtq | pacman -Rs - dnf autoremove apt autoremove zypper rm -u emerge --depclean
Download only pacman -Sw dnf download apt download zypper --download-only emerge --fetchonly
Action log /var/log/pacman.log dnf history /var/log/dpkg.log /var/log/zypp/history /var/log/portage
Package info (installed) pacman -Qi rpm -qi dpkg -s rpm -qi emerge -pv
Files of an installed package pacman -Ql rpm -ql dpkg -L rpm -ql equery files
Package owning a file pacman -Qo rpm -qf dpkg -S zypper search -f equery belongs
List installed packages pacman -Q dnf list installed dpkg -l zypper search --installed-only qlist -IC
Packages not in any repository pacman -Qm dnf list extras deborphan eix-test-obsolete
Packages with an update available pacman -Qu dnf check-update apt list --upgradable zypper list-updates emerge -uDNp @world
Hold a package IgnorePkg in /etc/pacman.conf exclude in dnf.conf apt-mark hold zypper al /etc/portage/package.mask
Verify installed packages pacman -Qk rpm -Va debsums rpm -Va equery check
Reinstall pacman -S dnf reinstall apt install --reinstall zypper install --force emerge -1O
Install a local package file pacman -U dnf install apt install zypper in emerge

Troubleshooting a damaged RPM-based system (Red Hat)

Check whether files are owned by a package:

rpm -qf /usr/local/lib/python3.6/site-packages
# file /usr/local/lib/python3.6/site-packages is not owned by any package

Reinstall all Python packages (prints the commands to review and run):

rpm -qa | grep -i python | xargs -- printf "sudo yum reinstall -U %s\n "

Check for binary or library corruption:

rpm -Va &> /tmp/rpmva.txt    # takes some time
egrep -v " c | d | g " /tmp/rpmva.txt | awk '{print $NF}' | sort | uniq | xargs rpm -qf 2> /dev/null | sort | uniq &> /tmp/pkgs.txt

Example output lines:

S.5....T.  c /etc/sysctl.conf
....L....  c /etc/nsswitch.conf
.M.......  g /etc/cni/net.d
.......T.    /boot/efi/EFI/redhat/grubx64.efi

Attribute flags (first column):

Flag Meaning
S file size differs
M mode differs (permissions and file type)
5 digest (formerly MD5 sum) differs
D device major/minor number mismatch
L readLink(2) path mismatch
U user ownership differs
G group ownership differs
T modification time differs
P capabilities differ

File type markers (second column): c configuration file, d documentation, g ghost file (content not in the package payload), l license, r readme.

Collect diagnostic data when yum or dnf misbehaves because of Python problems:

which python
env > /tmp/env.out
rpm -qf `which yum`
/usr/libexec/platform-python -c "import sys;print(sys.path)"
strace -fttTvyy -s 1024 -o /tmp/yum-repolist.strace yum repolist

If possible, move the contents of /usr/local/lib64/python3.6/site-packages and /usr/local/lib/python3.6/site-packages somewhere else (for example /tmp), then check that yum works again.

Find configuration files left by package updates (.rpmnew and .rpmsave):

find / -print | egrep "rpmnew$|rpmsave$"

Notes

Mastodon LLIMastodon SocialFosstodon