pacman Package Manager

pacman cheatsheet — install, update, remove packages on Arch Linux. pacman -S, pacman -Syu, pacman -Rs, pacman -Ss, pacman -Q. Full Arch Linux package management.

7 min read

What it is

pacman is the Arch Linux package manager, used for installing, upgrading, and removing software packages on Arch-based systems.

Installation

pacman is the default package manager for Arch Linux and its derivatives. It is installed automatically when you install an Arch-based distribution.

Core Concepts

  • Package: A bundle of files, configuration, and metadata required to run a specific piece of software.
  • Repository: A remote server that hosts packages. pacman synchronizes with these repositories to find and download packages.
  • Database: pacman maintains a local database of installed packages and available packages from synchronized repositories.
  • Sync: The process of downloading the latest package lists from the repositories.
  • Target: A package name or a group of packages.
  • Group: A collection of related packages that can be installed together (e.g., kde-applications).
  • Dependencies: Packages that another package requires to function correctly. pacman automatically handles installing dependencies.
  • Conflicts: Packages that cannot be installed at the same time as another package because they would interfere with each other.
  • Optional Dependencies: Packages that are not strictly required but provide additional functionality.
  • Provides: A capability that a package offers, which other packages might depend on.
  • Make dependency: A package required only during the build process of another package.
  • Check dependency: A package required to verify the integrity of another package after installation.

Commands / Usage

Synchronizing Package Databases

  • sudo pacman -Sy Synchronizes the local package database with the remote repositories. This is usually the first step before installing or upgrading packages.

  • sudo pacman -Syy Forces a refresh of all package databases, even if they appear to be up-to-date. Useful if you suspect the local database is out of sync.

Installing Packages

  • sudo pacman -S firefox Installs the firefox package and its dependencies.

  • sudo pacman -Syu Synchronizes the package databases and then upgrades all installed packages to their latest versions. This is the most common command for system updates.

  • sudo pacman -Su Upgrades all installed packages to their latest versions without synchronizing the package databases first. (Use with caution, -Syu is preferred).

  • sudo pacman -S package1 package2 Installs multiple packages at once.

  • sudo pacman -S --needed package1 Installs package1 only if it is not already installed or if the installed version is older than the one in the repository.

  • sudo pacman -S --asdeps package1 Installs package1 as an optional dependency. This is typically used by other packages.

  • sudo pacman -S --asexplicit package1 Marks package1 as explicitly installed, preventing it from being removed as an unneeded dependency later.

  • sudo pacman -S --overwrite '<path>' package_name Installs package_name and allows it to overwrite files at <path> that are managed by other packages. Use with extreme caution. Example: sudo pacman -S --overwrite '/usr/lib/lib*' package_name

Removing Packages

  • sudo pacman -R package_name Removes package_name but leaves its dependencies installed.

  • sudo pacman -Rs package_name Removes package_name and its dependencies that are not required by any other installed package.

  • sudo pacman -Rsc package_name Removes package_name, its dependencies that are not required by any other installed package, and also removes packages that depend on package_name. Use with extreme caution.

  • sudo pacman -Rsn package_name Removes package_name and its configuration files.

  • sudo pacman -Rns package_name Removes package_name, its dependencies that are not required by any other installed package, and its configuration files.

  • sudo pacman -Rdd package_name Removes package_name and ignores dependency checks. Use with extreme caution, as this can break your system.

Querying Packages

  • pacman -Q Lists all installed packages.

  • pacman -Q package_name Checks if package_name is installed and shows its version.

  • pacman -Qs keyword Searches installed packages for keyword.

  • pacman -Qi package_name Displays detailed information about an installed package.

  • pacman -Ql package_name Lists all files owned by an installed package_name.

  • pacman -Qo /path/to/file Finds which installed package owns the specified file.

  • pacman -Qm Lists installed packages that were not found in the sync databases (e.g., manually compiled packages).

  • pacman -Qe Lists explicitly installed packages.

  • pacman -Qd Lists packages installed as dependencies.

  • pacman -Qc Lists packages that have configuration files that differ from the installed version.

  • pacman -Qk Checks the integrity of all installed packages.

  • pacman -Qkk package_name Checks the integrity of package_name more thoroughly.

  • pacman -Ss keyword Searches for packages in the synchronized repositories that match keyword.

  • pacman -Si package_name Displays detailed information about a package available in the repositories.

  • pacman -Sl repository_name Lists all packages in a specific repository. Example: pacman -Sl core

  • pacman -Sg group_name Lists packages belonging to a specific package group.

Package Groups

  • sudo pacman -S group_name Installs all packages within a specified group. Example: sudo pacman -S gnome

Cleaning the Package Cache

  • sudo pacman -Sc Removes all packages from the cache that are no longer installed.

  • sudo pacman -Scc Removes all packages from the cache, including those that are still installed. Use with caution.

  • sudo paccache -r Removes all cached packages except for the three most recent versions of each. (Requires pacman-contrib package).

  • sudo paccache -rk 2 Removes all cached packages except for the two most recent versions of each. (Requires pacman-contrib package).

Other Operations

  • sudo pacman -D --asexplicit package_name Marks package_name as explicitly installed.

  • sudo pacman -D --asdeps package_name Marks package_name as a dependency.

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

  • sudo pacman -U /path/to/package1.pkg.tar.zst /path/to/package2.pkg.tar.zst Installs multiple local packages.

  • sudo pacman -F filename Searches for files in the file database. This requires the file database to be generated and synchronized first.

  • sudo pacman -Fy Synchronizes the file database.

  • sudo pacman -Fyy Forces a refresh of the file database.

  • sudo pacman -Syyu --noconfirm Synchronizes databases, upgrades all packages, and automatically confirms all prompts. Use with extreme caution.

Common Patterns

  • Full system upgrade: sudo pacman -Syu This is the most frequent command for keeping your Arch system up-to-date.

  • Search for a package: pacman -Ss <search_term> Example: pacman -Ss web browser

  • Find which package owns a file: pacman -Qo /usr/bin/vim Useful when you encounter a file and want to know which package installed it.

  • Remove a package and its unneeded dependencies: sudo pacman -Rs <package_name> Example: sudo pacman -Rs vlc

  • Install a package and mark it as explicitly installed: sudo pacman -S --asexplicit <package_name> This prevents it from being removed if it’s only a dependency of another package you later uninstall.

  • Reinstall a package (useful for fixing broken packages): sudo pacman -S <package_name> This will reinstall the package from the repository, overwriting existing files.

  • Clean up old package cache: sudo paccache -r (Requires pacman-contrib) Keeps the last 3 versions of each package.

  • View installed files of a package: pacman -Ql <package_name> Example: pacman -Ql nano

  • Check integrity of installed packages: sudo pacman -Qk Followed by sudo pacman -Qkk for a more thorough check if issues are found.

  • Install a package from a local .pkg.tar.zst file: sudo pacman -U ~/Downloads/my_package-1.0-1-x86_64.pkg.tar.zst

  • Remove a package and its configuration files: sudo pacman -Rsn <package_name> Example: sudo pacman -Rsn gnome-tweaks

Gotchas

  • Partial Upgrades: Running pacman -Sy <package> without -u can lead to a partially upgraded system if the package you’re installing requires newer libraries than what’s currently installed. Always use sudo pacman -Syu for system-wide upgrades.

  • --noconfirm: Using --noconfirm with pacman -Syu or other modification commands can lead to unintended consequences if you don’t fully understand what’s being changed. It’s best to review prompts and confirm actions manually.

  • AUR Helpers: pacman itself does not manage packages from the Arch User Repository (AUR). You need an AUR helper (like yay, paru, etc.) for that. These helpers often use pacman internally but have their own syntax.

  • Configuration Files (.pacsave, .pacnew): When upgrading packages that include new or modified configuration files, pacman might save your existing configuration as .pacsave and the new one as .pacnew. It is your responsibility to merge these files if necessary. Tools like meld or diff can help.

  • Force Overwriting Files: Using pacman -S --overwrite should be done with extreme caution. It can break package management if used incorrectly, leading to files being managed by multiple packages or unexpected behavior.

  • pacman -Rdd: This command bypasses all dependency checks. It is highly dangerous and can easily render your system unusable. Only use it as a last resort and with full knowledge of the consequences.

  • Repository Synchronization: If you have issues installing or updating, the first step is always to ensure your local package database is synchronized (sudo pacman -Syyu). Sometimes, temporarily adding a mirror to the top of your /etc/pacman.d/mirrorlist can resolve slow download speeds or connection errors.