Getting started with pacman

Getting Started with pacman on Arch Linux Distributions

guide

Pacman is Arch Linux’s native package manager, engineered to be both lightweight and powerful. After installing Arch, the first priority is to keep pacman and the system up‑to‑date and to fine‑tune the mirror list for optimal download speeds. This guide walks you through the core tasks every new user should know: updating, searching, installing, removing, cleaning the cache, and configuring pacman, along with common pitfalls and best practices.

  1. Update the system
    sudo pacman -Syu

    • -S syncs packages, -y refreshes the package list, and -u upgrades all out‑of‑date packages.
    • Run this immediately after a fresh install to pull in the latest packages and security patches.
    • For a forced refresh of the mirror list, use sudo pacman -Syyu (the double y forces a complete database refresh).
  2. Search for packages
    pacman -Ss <search-term>

    • -Ss searches the remote repositories.
    • For detailed information on a specific package, use pacman -Si <pkg>.
  3. Install packages
    sudo pacman -S <package-name>

    • Pacman automatically resolves dependencies.
    • List multiple packages separated by spaces.
    • Add --needed to skip reinstalling packages that are already present.
  4. Remove packages
    sudo pacman -R <package-name>

    • -R removes the package but leaves its dependencies.
    • -Rs removes the package and any dependencies that were installed only for it and are no longer needed.
    • -Rns also removes configuration files left behind by the package.
  5. Clean the package cache
    sudo pacman -Sc

    • -Sc removes all cached versions of packages except the current one.
    • For a more aggressive cleanup that deletes all cached packages—including the current ones—use -Scc. Use this with caution.
  6. View package status
    pacman -Qi <package-name>

    • Shows installed package details.
    • pacman -Qdt lists orphaned dependencies that can be safely removed.
  7. Configure pacman

    • Edit /etc/pacman.conf to enable or disable features such as Color, VerbosePkgLists, or ParallelDownloads.
    • Use pacman-mirrors to generate a fast mirror list:
      sudo pacman-mirrors --fasttrack && sudo pacman -Syyu
  8. Common troubleshooting

    • If a transaction fails, run pacman -Syy to force a refresh of the package database.
    • Resolve broken dependencies with pacman -D --asdeps <pkg> or pacman -D --asexplicit <pkg>.
    • For a corrupted database, delete /var/lib/pacman/db.lck and retry.
  9. Using the Arch Wiki

    • The Arch Wiki’s Pacman page is the definitive reference, covering advanced options, hooks, and the package signing process.
    • The “Pacman” section also explains how to use pacman with AUR helpers like yay or paru for community packages.
  10. Security best practices

    • Keep pacman and the system updated to mitigate vulnerabilities.
    • Verify package signatures; pacman checks them automatically if the keyring is properly installed (pacman-key --init && pacman-key --populate archlinux).
    • Use pacman -Syu --noconfirm only in scripts, not interactively, to avoid accidental upgrades.

By mastering these commands and concepts, you can confidently manage software on Arch Linux, maintain system stability, and keep your system secure.