Skip to content

Pacman

Chapter 27: pacman - Arch Linux Package Manager

Section titled “Chapter 27: pacman - Arch Linux Package Manager”

Comprehensive Guide to Arch Linux Package Management

Section titled “Comprehensive Guide to Arch Linux Package Management”

pacman is the official package manager for Arch Linux and its derivatives (Manjaro, EndeavourOS, etc.). It’s known for its simplicity, speed, and rolling release model.

pacman Architecture
+------------------------------------------------------------------+
| |
| pacman Components: |
| |
| +-------------------------------------------------------------+|
| | pacman (CLI tool) ||
| | - Package installation/removal ||
| | - Database synchronization ||
| | - Dependency resolution ||
| +-------------------------------------------------------------+|
| | |
| v |
| +-------------------------------------------------------------+|
| | libalpm (Backend) ||
| | - Package operations ||
| | - Script hooks ||
| | - Signature verification ||
| +-------------------------------------------------------------+|
| | |
| v |
| +-------------------------------------------------------------+|
| | Package Database ||
| | - /var/lib/pacman/sync/ ||
| | - Local package cache /var/cache/pacman/pkg/ ||
| +-------------------------------------------------------------+|
| |
| Key Features: |
| +----------------------------------------------------------+ |
| | • Rolling release model | |
| | • Dependency resolution | |
| | • Signature verification (GPG) | |
| | • Hook system for automation | |
| | • Very fast and lightweight | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

Terminal window
# Sync database (refresh package lists)
sudo pacman -Sy
# Update system (sync and upgrade)
sudo pacman -Syu
# Sync databases without upgrade
sudo pacman -Sy
# Force refresh
sudo pacman -Syy
Terminal window
# Install single package
sudo pacman -S package_name
# Install multiple packages
sudo pacman -S package1 package2 package3
# Install from specific repository
sudo pacman -S extra/package_name
sudo pacman -S core/package_name
sudo pacman -S community/package_name
# Install from AUR (using base-devel)
sudo pacman -S --needed base-devel
git clone aur package
cd package
makepkg -si
# Reinstall package
sudo pacman -S package_name
# Install from local file
sudo pacman -U /path/to/package.pkg.tar.zst
# Download only (no install)
sudo pacman -Sw package_name
Terminal window
# Remove package (keep dependencies)
sudo pacman -R package_name
# Remove package and dependencies (not required by others)
sudo pacman -Rs package_name
# Remove package, dependencies, and config files
sudo pacman -Rns package_name
# Remove package and all packages depending on it
sudo pacman -Rc package_name
# Remove orphaned packages (no longer needed)
sudo pacman -Rsn $(pacman -Qdtq)
# Remove unused packages (orphans)
sudo pacman -Sc # Clean cache
Terminal window
# List all installed packages
pacman -Q
# List explicitly installed packages
pacman -Qe
# List native packages (from core/extra/community)
pacman -Qn
# List foreign packages (AUR)
pacman -Qm
# Search for package
pacman -Ss keyword
pacman -Ss "^package-name"
# Search installed packages
pacman -Qs keyword
# Show package info
pacman -Qi package_name
pacman -Qii package_name # with backup info
# Show package file list
pacman -Ql package_name
# Show package dependencies
pacman -Si package_name
# Check package files (owned by what)
pacman -Qo /path/to/file
# List files not owned by any package
pacman -Qkk # Check all
Terminal window
# Clean cache (remove old packages)
sudo pacman -Sc
# Clean all packages from cache
sudo pacman -Scc
# List packages in cache
ls /var/cache/pacman/pkg/
# Keep only latest version
sudo pacman -Sc

Terminal window
# Main configuration file
sudo nano /etc/pacman.conf
# Enable parallel downloads
ParallelDownloads = 5
# Enable colors
Color
# Enable verbose package lists
VerbosePkgLists
# Enable ILoveCandy (pacman animation)
# Add to end of file or uncomment
# ILoveCandy
# Enable check space during installation
CheckSpace
# Database path (for multiple installations)
# DBPath = /var/lib/pacman/
# Cache path
# CacheDir = /var/cache/pacman/pkg/
# Log file
# LogFile = /var/log/pacman.log
# Architecture
Architecture = x86_64
# or
Architecture = i686
/etc/pacman.conf
[core]
# Core packages
Include = /etc/pacman.d/mirrorlist
[extra]
# Extra packages
Include = /etc/pacman.d/mirrorlist
[community]
# Community packages
Include = /etc/pacman.d/mirrorlist
# Multilib (32-bit support on x86_64)
[multilib]
Include = /etc/pacman.d/mirrorlist
# Testing repositories
[testing]
Include = /etc/pacman.d/mirrorlist
[community-testing]
Include = /etc/pacman.d/mirrorlist
Terminal window
# Edit mirrors
sudo nano /etc/pacman.d/mirrorlist
# Use fastest mirror
sudo pacman -S reflector
# Generate mirrorlist
sudo reflector --country US --latest 10 --sort rate --save /etc/pacman.d/mirrorlist
# Rank mirrors by speed
sudo pacman -S pacman-contrib
rankmirrors -6 /etc/pacman.d/mirrorlist
# Uncomment all mirrors (select all)
# In vim: :%s/^#//

Terminal window
# Check package signature
pacman -Qi package_name | grep Signature
# List trusted keys
pacman-key --list-keys
# Refresh keys
sudo pacman-key --refresh-keys
# Add key
sudo pacman-key --recv-keys keyid
# Sign key
sudo pacman-key --lsign keyid
# Verify database
sudo pacman -Sy --verify
# Disable signature checking (NOT RECOMMENDED)
# In /etc/pacman.conf:
# SigLevel = Never

Terminal window
# Hook directory
ls /usr/lib/alpm/hooks/
# User hooks
sudo mkdir -p /etc/pacman.d/hooks
# Example: Update grub after kernel upgrade
# /etc/pacman.d/hooks/50-update-grub.hook
[Trigger]
Type = Package
Operation = Upgrade
Target = linux
[Action]
Description = Updating GRUB for new kernel...
When = PostTransaction
Exec = /usr/bin/grub-mkconfig -o /boot/grub/grub.cfg
Terminal window
# Rebuild initramfs after kernel upgrade
[Trigger]
Type = Package
Operation = Upgrade
Target = linux
[Action]
Description = Rebuilding initramfs...
When = PostTransaction
Exec = /usr/bin/mkinitcpio -P
# Update systemd units
[Trigger]
Type = Package
Operation = Install
Operation = Upgrade
Target = systemd
[Action]
Description = Reloading systemd daemon...
When = PostTransaction
Exec = /usr/bin/systemctl daemon-reload

Terminal window
# Install base-devel (needed for building AUR packages)
sudo pacman -S --needed base-devel
# Using yay (most popular AUR helper)
# Install yay
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
# Common yay commands
yay -Syu # Update system + AUR
yay -Ss keyword # Search
yay -S package # Install
yay -Rsc package # Remove with deps
yay -Yc # Clean unused deps
yay -Ycc # Clean all cache
# Using paru (Rust-based alternative)
git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si
# Using pamac (GUI)
sudo pacman -S pamac
# Using aurutils
sudo pacman -S aurutils
Terminal window
# Clone package
git clone https://aur.archlinux.org/package_name.git
cd package_name
# Review PKGBUILD
cat PKGBUILD
nano PKGBUILD
# Build and install
makepkg -si
# Or just build
makepkg -s
# Install local package
sudo pacman -U *.pkg.tar.zst

Terminal window
# Fix "target not found"
sudo pacman -Syyu
# Fix "package not found" in sync
sudo pacman -Syy && sudo pacman -S package
# Fix "could not resolve host"
# Check DNS
ping archlinux.org
# Edit /etc/resolv.conf if needed
# Fix "invalid or corrupted package"
sudo pacman -Scc
sudo pacman -Syu
# Fix "conflicting files"
# Overwrite
sudo pacman -S --overwrite "*" package
# Fix dependency issues
sudo pacman -Syu --debug
# Recover from failed update
# Boot from Arch ISO
# Mount filesystem
# pacman -Syu --root /mnt
# Check for conflicts
pacman -Qkk
Terminal window
# Reinstall all packages
sudo pacman -S $(pacman -Qq | grep -v "$(pacman -Qmq)")
# Restore pacman database
# From backup
sudo cp /var/lib/pacman/local/*.tar.zst backup/
# Or use arch-chroot
sudo arch-chroot /mnt
pacman -Syu

  1. What is pacman?

    • Official package manager for Arch Linux
  2. How do you update the system?

    • sudo pacman -Syu
  3. What is the difference between -S and -U?

    • -S installs from repository; -U installs from local file
  4. What is AUR?

    • Arch User Repository - community-maintained packages
  5. How do you remove orphaned packages?

    • sudo pacman -Rsn $(pacman -Qdtq)
  1. What is the rolling release model?

    • Continuous updates without major version jumps
  2. How do hooks work in pacman?

    • Trigger actions on package operations
  3. What is libalpm?

    • Backend library for pacman
  4. How do you verify package signatures?

    • pacman-key management
  5. What are hooks vs scripts in PKGBUILD?

    • Hooks are system-level, scripts are package-specific

Quick Reference
+------------------------------------------------------------------+
| |
| Basic Commands: |
| +----------------------------------------------------------+ |
| | pacman -Syu | Update system | |
| | pacman -S package | Install package | |
| | pacman -R package | Remove package | |
| | pacman -Ss keyword | Search packages | |
| | pacman -Q | List installed | |
| +----------------------------------------------------------+ |
| |
| Flags: |
| +----------------------------------------------------------+ |
| | -y | Sync database | |
| | -u | Upgrade packages | |
| | -s | Search | |
| | -i | Info | |
| | -l | List files | |
| | -r | Remove | |
| | -n | Native packages only | |
| | -m | Foreign packages (AUR) | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+