pacman (Package Manager) is the central tool and heart of every Arch Linux installation. Developed by Judd Vinet, Pacman combines a simple binary package format with a declarative, fast dependency management via the library libalpm (Arch Linux Package Management).
Pacman differs fundamentally from dpkg/apt or rpm/dnf: Instead of nesting complex pre- and post-installation scripts arbitrarily deep, Pacman relies on pre-compiled tar.zst archives, strict metadata, and declarative ALPM hooks. Administration is direct, transparent, and extremely performant.
This guide is part of our Arch Linux series and walks you through every aspect of Pacman: from configuration in /etc/pacman.conf to basic operations (sync, search, install, remove) to advanced topics like ALPM hooks, dependency trees with pactree, GPG keyring management, and targeted troubleshooting for package conflicts.
π‘ Prerequisites: A running Arch Linux system with sudo privileges and basic familiarity with the Linux terminal.
The Pacman and ALPM Architecture
Pacman divides its tasks into clearly defined layers:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PACMAN & LIBALPM ARCHITECTURE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 1. CONFIGURATION: /etc/pacman.conf & /etc/pacman.d/ β
β 2. DATABASES: /var/lib/pacman/sync/ (core, extra, multi) β
β 3. CACHE: /var/cache/pacman/pkg/ (*.pkg.tar.zst) β
β 4. HOOKS: /etc/pacman.d/hooks/ & /usr/share/libalpm/ β
β 5. GPG KEYS: /etc/pacman.d/gnupg/ (pacman-key) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. Configuration in /etc/pacman.conf
Global Pacman control is managed through the file /etc/pacman.conf. This is where global options, color output, download parameters, and active repositories are defined.
Open the file for viewing or editing:
sudo nano /etc/pacman.conf
Recommended Global Options
[options]
# Prevents accidental removal of vital core packages
HoldPkg = pacman glibc
# Checks before transactions whether enough free space exists on target partitions
CheckSpace
# Enables colored terminal output and the Pacman progress bar
Color
ILoveCandy
# Enable parallel downloads (massive speed improvement)
ParallelDownloads = 5
# Strict signature verification for maximum security
SigLevel = Required DatabaseOptional
LocalFileSigLevel = Optional
ParallelDownloads = 5: Downloads up to 5 packages simultaneously, drastically speeding up system updates.ILoveCandy: A popular visual Easter egg that transforms the standard progress bar into an animated Pacman animation.CheckSpace: Pre-calculates disk space requirements for all target mounts and safely aborts transactions on low storage.
Official Repositories
Arch Linux structures its software into clearly separated official repositories:
# The foundation: kernel, init system, base tools, compiler
[core]
Include = /etc/pacman.d/mirrorlist
# All other official applications: desktop environments, browsers, server daemons
[extra]
Include = /etc/pacman.d/mirrorlist
# 32-bit libraries for 64-bit systems (e.g., for Steam, Wine, 32-bit drivers)
[multilib]
Include = /etc/pacman.d/mirrorlist
π‘ Note on the
[community]repository: Until May 2023, a separate[community]repository existed. Arch Linux consolidated its repository structure and fully integrated all community packages into[extra]. The[community]entry is no longer needed in modern installations.
Optimize Mirrorlist with reflector
The file /etc/pacman.d/mirrorlist controls which servers Pacman downloads packages from. A geographically close and up-to-date mirror list prevents slow downloads:
# Install reflector
sudo pacman -S reflector
# Generate top 10 German HTTPS mirrors
sudo reflector --country Germany --latest 10 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
2. Basic Operations: The Main Modes
Pacman controls its main operations via uppercase flags:
-S(Sync): Search, download, install, and update packages from remote repositories.-R(Remove): Remove installed packages and dependencies.-Q(Query): Search the local package database for installed packages and files.-F(Files): Search for files in remote repositories (file ownership).-D(Database): Modify metadata of installed packages (e.g., install reason).
Synchronize Package Databases and Perform Upgrades
# Full system update (Sync + Refresh + Upgrade)
sudo pacman -Syu
# If repositories were switched or the cache is desynchronized:
sudo pacman -Syyu
β οΈ Never use
pacman -Sywithout-u: Synchronizing the database in isolation (-Sy) followed by installing a single package (-S <package>) leads to a Partial Upgrade. Since newer libraries are installed while the rest of the system remains outdated, existing binaries break (Shared Library Mismatch).
Safe Update Check Without Root: checkupdates
To check whether updates are available without synchronizing the local system database, use checkupdates from the pacman-contrib package:
# Checks remotely for available updates (safe for scripts and status bars)
checkupdates
3. Searching and Analyzing Packages
Search Remote Repositories (-S)
# Search for packages by name or description
pacman -Ss nginx
# Display detailed remote package information before installation
pacman -Si nginx
Example output of pacman -Si nginx:
Repository : extra
Name : nginx
Version : 1.26.1-1
Description : Lightweight HTTP server and IMAP/POP3 proxy server
Architecture : x86_64
URL : https://nginx.org
Licenses : BSD-2-Clause
Groups : None
Provides : http-server
Depends On : pcre2 zlib openssl geoip mailcap
Optional Deps : None
Conflicts With : None
Replaces : None
Download Size : 540.22 KiB
Installed Size : 1.68 MiB
Packager : Arch Linux Package Maintainers
Build Date : Tue 23 Jul 2024 02:10:00 PM CEST
Query Local Database (-Q)
# List all manually and explicitly installed packages
pacman -Qe
# List all packages installed as dependencies
pacman -Qd
# Display detailed information about an already installed package
pacman -Qi nginx
# List all files belonging to an installed package
pacman -Ql nginx
# Find out which package provides a specific file on disk
pacman -Qo /usr/bin/htop
# Output: /usr/bin/htop is owned by htop 3.3.0-1
Visualize Dependency Trees with pactree
To analyze the exact dependency hierarchy of a package:
# pacman-contrib provides pactree
pactree nginx
# Reverse tree: Which installed packages depend on openssl?
pactree -r openssl
4. Installation and Targeted Removal
Install Packages
# Install a single or multiple packages
sudo pacman -S htop neovim git
# Download a package only, without extracting/installing
sudo pacman -Sw wireshark-qt
# Install a local or manually built package file (*.pkg.tar.zst)
sudo pacman -U /path/to/package-1.0-1-x86_64.pkg.tar.zst
Remove Packages Cleanly and Without Residue
When removing software, it is crucial not to leave orphaned dependencies and unused configuration files on the system:
# Standard removal (leaves dependencies and configurations)
sudo pacman -R packagename
# BEST PRACTICE: Removes the package, its unused dependencies (-s)
# and global configuration files (-n)
sudo pacman -Rns packagename
-s(Recursive): Removes all dependencies no longer needed by any other installed package.-n(NoSave): Deletes configuration files instead of creating.pacsavefiles.
Change Install Reason: --asdeps and --asexplicit
If you manually installed a package that is actually only a temporary dependency (or vice versa), you can correct the status afterward:
# Mark package as dependency (will be recognized as orphan during cleanup)
sudo pacman -D --asdeps libxml2
# Mark package as explicitly wanted by the administrator
sudo pacman -D --asexplicit neovim
5. System Maintenance: Orphans, Cache & ALPM Hooks
Clean Up Orphaned Packages (Orphans)
Orphans are packages installed as dependencies whose parent application has since been uninstalled:
# List all orphaned packages
pacman -Qtdq
# Remove all orphaned packages completely
sudo pacman -Rns $(pacman -Qtdq)
Automate Package Cache Management with paccache
Pacman retains all downloaded packages in /var/cache/pacman/pkg/. To save disk space while keeping the ability to roll back to a previous version (downgrade):
# Keep the last 2 versions of each package
sudo paccache -r -k 2
# Remove all versions of uninstalled packages
sudo paccache -ruk0
# Enable systemd timer for weekly cleanup
sudo systemctl enable --now paccache.timer
Understand and Create ALPM Transaction Hooks
Pacman executes so-called ALPM hooks during transactions (install, upgrade, remove). System hooks are located under /usr/share/libalpm/hooks/, custom administrator hooks under /etc/pacman.d/hooks/.
Example: Automatic security audit with arch-audit after every upgrade in /etc/pacman.d/hooks/90-arch-audit.hook:
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Description = Checking installed packages for known CVE vulnerabilities...
When = PostTransaction
Exec = /usr/bin/arch-audit
6. GPG Keyring & Troubleshooting
Error: "Invalid or corrupted package signature"
When a signature error occurs, the local Arch keyring is usually outdated or desynchronized:
# 1. Update keyring
sudo pacman -Sy archlinux-keyring
# 2. If keyring is corrupted: Reinitialize
sudo rm -rf /etc/pacman.d/gnupg
sudo pacman-key --init
sudo pacman-key --populate archlinux
sudo pacman-key --refresh-keys
Error: "Failed to lock database (db.lck)"
If Pacman aborts during a transaction (e.g., due to power loss or Ctrl+C), the lock file /var/lib/pacman/db.lck remains.
# First check whether another Pacman process is still running
pgrep -l pacman
# If no process is active: Safely remove lock file
sudo rm /var/lib/pacman/db.lck
Error: "File conflict: /usr/lib/... exists in the filesystem"
When a file exists that according to the database belongs to no package (e.g., from previous manual make install calls):
# 1. Check who owns the file
pacman -Qo /path/to/file
# 2. If the file is orphaned, back it up and overwrite
sudo pacman -Syu --overwrite "/path/to/file"
Command Reference (Cheatsheet)
| Task | Command |
|---|---|
| Update system | sudo pacman -Syu |
| Search package | pacman -Ss <searchterm> |
| Package info (remote) | pacman -Si <package> |
| Install package | sudo pacman -S <package> |
| Remove package cleanly | sudo pacman -Rns <package> |
| Install local package | sudo pacman -U <file.pkg.tar.zst> |
| Find file owner | pacman -Qo /path/to/file |
| List package files | pacman -Ql <package> |
| Remove orphans | sudo pacman -Rns $(pacman -Qtdq) |
| Clean cache | sudo paccache -r -k 2 |
| Check updates safely | checkupdates |
Further Resources
Arch Linux Installation and Basic Configuration Arch Linux: Best Practices and Tips for System Maintenance Arch Linux: System Hardening and Security β Best Practices Arch Linux: Advanced Security Features and Maintenance Official Arch Wiki: Pacman Documentation Arch Wiki: Pacman Tips and Tricks
Conclusion
The package manager pacman is the central nervous system of Arch Linux. Mastering its mechanisms, flags, and configuration options gives you the most important tool for keeping a rolling-release system stable, lean, and performant long-term.
In this first part of our series, you learned why partial upgrades must be avoided, how to manage signature keys with pacman-key, and how to cleanly clean up orphaned dependencies and package caches. With this knowledge, you can resolve package conflicts with confidence and keep your system in optimal condition.
π‘ Practical tip: Run
checkupdatesbefore every system upgrade to risk-free check for pending updates, and always keep at least two previous versions in the cache so you can perform a quick downgrade withpacman -Uin an emergency.
In the next article of our series, we put this knowledge to the test: In Arch Linux Installation and Basic Configuration we build a complete system from scratch β including UEFI, BTRFS subvolumes, disk encryption, and basic network configuration.