Pacman Guide (Arch Linux)

Pacman Guide (Arch Linux)

Arch Linux uses a rolling-release model: there are no major version upgrades, just a continuous stream of package updates. Pacman is the tool that manages this stream. Its design is deliberately minimal — tight flags, fast operations, no automatic handling of optional dependencies you did not ask for. Understanding the flag system makes the whole thing click.

The flag system

Pacman organises operations into four main groups, each triggered by an uppercase letter:

-S  Sync       (install, update, search the repos)
-R  Remove     (uninstall packages)
-Q  Query      (search the local package database)
-U  Upgrade    (install a local .pkg.tar.zst file)
-D  Database   (manipulate package reason flags)
-F  Files      (search which package owns a file)

Lowercase letters modify the operation: -y refreshes the sync database, -u upgrades, -s searches or removes dependencies recursively, -q produces quiet output.

Installing and upgrading

# Sync database and upgrade everything (the standard update command)
sudo pacman -Syu

# Force a full database refresh (use after changing mirrors)
sudo pacman -Syyu

# Install a package
sudo pacman -S nginx

# Install multiple packages
sudo pacman -S nginx postgresql redis

# Install without upgrading (not recommended, can cause partial upgrades)
sudo pacman -S --needed nginx

# Reinstall a package
sudo pacman -S --needed nginx

# Download a package without installing
sudo pacman -Sw nginx

# Install from a local file
sudo pacman -U /path/to/package.pkg.tar.zst

On Arch, partial upgrades are unsupported. Always run pacman -Syu before installing new packages, not pacman -S packagename alone. Installing a package against a stale system can cause library mismatches.

Removing packages

# Remove a package only
sudo pacman -R nginx

# Remove a package and its unneeded dependencies
sudo pacman -Rs nginx

# Remove a package, its dependencies, and config files (.pacsave files)
sudo pacman -Rns nginx

# Remove a package that something else depends on (dangerous: breaks dependents)
sudo pacman -Rdd nginx

# Preview what would be removed before committing
sudo pacman -Rns --print nginx

-Rns is the right command for most removals. It cleans up dependencies and configuration files in one step.

Querying installed packages

# List all installed packages
pacman -Q

# List explicitly installed packages (not pulled in as deps)
pacman -Qe

# List packages installed from the AUR or local files
pacman -Qm

# List packages installed as dependencies
pacman -Qd

# List orphaned packages (deps no longer needed by anything)
pacman -Qtd

# Search installed packages by name
pacman -Qs nginx

# Show information about an installed package
pacman -Qi nginx

# List files installed by a package
pacman -Ql nginx

# Find which installed package owns a file
pacman -Qo /usr/sbin/nginx

# Check if a package is installed
pacman -Qi nginx &>/dev/null && echo installed || echo not installed

Querying the sync database

# Search for a package in the repos by name or description
pacman -Ss nginx
pacman -Ss "web server"

# Show information about a package in the repos
pacman -Si nginx

# List all packages in the repos (very long output)
pacman -Sl

# List packages in a specific repo
pacman -Sl extra
pacman -Sl core

# Find which package provides a file (requires synced file database)
pacman -F /usr/sbin/nginx         # search in repo file database
sudo pacman -Fy                   # update the file database first

# Check for available upgrades without installing
pacman -Qu

Cleaning up

# Find all orphaned packages
pacman -Qtdq

# Remove all orphans in one command
sudo pacman -Rns $(pacman -Qtdq)

# Clean the package cache (keeps the 3 most recent versions by default)
sudo paccache -r

# Remove all cached versions except the most recent
sudo paccache -rk1

# Remove all cached packages for packages no longer installed
sudo paccache -ruk0

# Clear the entire package cache
sudo pacman -Sc        # cached packages not currently installed
sudo pacman -Scc       # everything in the cache

# Check pacman's log for recent actions
tail -50 /var/log/pacman.log

The package cache at /var/cache/pacman/pkg/ accumulates quickly on a rolling-release system. Running paccache -r (from the pacman-contrib package) weekly keeps it under control while retaining rollback options.

Mirror management

Package download speed depends entirely on the quality of your mirrors. Slow downloads usually mean it is time to update your mirror list.

# Install reflector (mirror ranking tool)
sudo pacman -S reflector

# Generate a mirror list ranked by speed, saved to the config
sudo reflector --country 'United States' --age 12 --protocol https \
  --sort rate --save /etc/pacman.d/mirrorlist

# Preview the list before saving
reflector --country 'United States' --age 12 --protocol https --sort rate

# Backup and manually edit the mirrorlist
sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
sudo nano /etc/pacman.d/mirrorlist

# After updating mirrors, force a full sync
sudo pacman -Syyu

The AUR (Arch User Repository)

The AUR hosts PKGBUILDs: shell scripts that describe how to build and package software not in the official repos. There are over 80,000 AUR packages.

Do not install AUR packages without reading the PKGBUILD first. A PKGBUILD runs arbitrary shell code with your user privileges during the build process. Reviewing it is not optional.

Manual AUR install

# Install the base-devel group first (needed for makepkg)
sudo pacman -S --needed base-devel git

# Clone the AUR package repository
git clone https://aur.archlinux.org/some-package.git
cd some-package

# Read the PKGBUILD before building
cat PKGBUILD

# Build and install
makepkg -si
# -s: install missing dependencies via pacman
# -i: install the built package

# Clean up build files
makepkg --clean

AUR helpers: yay and paru

AUR helpers wrap pacman and handle AUR packages transparently:

# Installing yay (a popular AUR helper)
sudo pacman -S --needed base-devel git
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

# Installing paru (a newer Rust-based helper)
git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si

# Using yay (same flags as pacman, plus AUR support)
yay -Syu                          # upgrade everything including AUR
yay -S some-aur-package           # install from AUR
yay -Ss search-term               # search repos + AUR
yay -Rns package                  # remove (delegates to pacman)

# paru works identically to yay
paru -Syu
paru -S some-aur-package

Both yay and paru show the PKGBUILD before building and support the -Syu upgrade workflow for both official and AUR packages. Choose one and stick with it — mixing helpers can create confusion about what is installed from where.

makepkg in depth

makepkg is not just for AUR packages. You can use it to rebuild official Arch packages with patches, or to build packages from any PKGBUILD.

# Build without installing
makepkg

# Build and install
makepkg -i

# Build, install dependencies, and install
makepkg -si

# Build without verifying checksums (not recommended in production)
makepkg --skipchecksums

# Build as a specific user (makepkg refuses to run as root)
# If you are accidentally in a root shell:
sudo -u builduser makepkg -si

# Sign the built package with your GPG key
makepkg --sign

# Build a package and install all optional dependencies too
makepkg -si --asdeps

All packages are built in /tmp by default (or a custom BUILDDIR in /etc/makepkg.conf). Build artifacts are placed in the current directory.

Package reason flags

Pacman tracks whether a package was installed explicitly (you asked for it) or as a dependency (another package required it). This is how orphan detection works.

# Mark a package as explicitly installed
sudo pacman -D --asexplicit nginx

# Mark a package as a dependency
sudo pacman -D --asdep nginx

# See the reason for all installed packages
pacman -Qi | grep -E 'Name|Install Reason'

When you install something to test it and decide to keep it permanently, mark it explicit so it does not get removed during orphan cleanup.

pacman.conf

Pacman’s configuration lives at /etc/pacman.conf. Key settings:

# View the config
cat /etc/pacman.conf

# Enable the multilib repo (32-bit libraries, needed for Steam, Wine)
# Uncomment these two lines in /etc/pacman.conf:
# [multilib]
# Include = /etc/pacman.d/mirrorlist

# Enable coloured output
# Uncomment: Color

# Show package download progress
# Uncomment: VerbosePkgLists

# Parallel downloads (set to number of simultaneous downloads)
# ParallelDownloads = 5

# After editing pacman.conf, sync to apply
sudo pacman -Syu

Downgrading packages

Arch does not have a stable branch, so occasionally an update breaks something. Downgrading to a previously cached version is straightforward:

# List cached versions of a package
ls /var/cache/pacman/pkg/ | grep nginx

# Install a specific cached version
sudo pacman -U /var/cache/pacman/pkg/nginx-1.24.0-1-x86_64.pkg.tar.zst

# If the package is not in cache, use the downgrade tool from AUR
yay -S downgrade
sudo downgrade nginx

# Hold the package at the downgraded version
# Add to IgnorePkg in /etc/pacman.conf:
# IgnorePkg = nginx

Quick reference

# System upgrade
sudo pacman -Syu

# Install / remove
sudo pacman -S pkg
sudo pacman -Rns pkg

# Search
pacman -Ss term         # repos
pacman -Qs term         # installed

# Query
pacman -Qi pkg          # info
pacman -Ql pkg          # files
pacman -Qo /path/file   # who owns this file
pacman -Qtdq            # orphans

# AUR
yay -Syu                # upgrade everything including AUR
yay -S aur-package
makepkg -si             # build and install from PKGBUILD

# Cleanup
sudo pacman -Rns $(pacman -Qtdq)    # remove orphans
sudo paccache -r                     # clean package cache

Pacman’s terseness is a feature. Once the letter codes are memorised, every operation is a short command. The discipline of reading PKGBUILDs before installing and always upgrading the full system before adding new packages keeps a rolling-release Arch install stable over time.

Frequently Asked Questions

What is pacman in Linux?

Pacman is the package manager for Arch Linux and Arch-based distributions like Manjaro and EndeavourOS. It uses a simple command-line interface with single-letter operation flags (-S to sync/install, -R to remove, -Q to query). Pacman manages binary packages from the official Arch repositories and integrates with the AUR (Arch User Repository) via helper tools like yay or paru.

What is the difference between pacman -Syu and pacman -Syyu?

pacman -Syu syncs the package database and upgrades all installed packages. The lowercase y refreshes the package database once. pacman -Syyu forces a full refresh of the package database even if pacman thinks it is already up to date. Use -Syyu when you switch mirrors or suspect the database is corrupted. For routine upgrades, -Syu is sufficient.

What is the AUR and how do I use it?

The AUR (Arch User Repository) is a community-driven repository of PKGBUILDs: shell scripts that describe how to download, compile, and package software not in the official Arch repos. You cannot install AUR packages directly with pacman. Instead, you clone the PKGBUILD, review it, run makepkg to build a .pkg.tar.zst package, and then install it with pacman -U. AUR helpers like yay and paru automate this process.

How do I remove a package and its dependencies in Arch Linux?

Use pacman -Rs packagename. The -s flag removes packages that were installed as dependencies of the target package and are no longer required by anything else. Without -s, only the specified package is removed. Use pacman -Rns to also remove the package configuration files (the “n” flag removes .pacsave files).

How do I find orphaned packages in Arch Linux?

Run pacman -Qtdq to list all orphaned packages — those that were installed as dependencies but are no longer required by any explicitly installed package. To remove them all at once: sudo pacman -Rns $(pacman -Qtdq). Run this periodically to keep the system clean, especially after removing applications that pulled in many dependencies.