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”26.1 Understanding pacman
Section titled “26.1 Understanding pacman”What is pacman?
Section titled “What is pacman?”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 | || +----------------------------------------------------------+ || |+------------------------------------------------------------------+26.2 Basic pacman Commands
Section titled “26.2 Basic pacman Commands”Package Synchronization
Section titled “Package Synchronization”# Sync database (refresh package lists)sudo pacman -Sy
# Update system (sync and upgrade)sudo pacman -Syu
# Sync databases without upgradesudo pacman -Sy
# Force refreshsudo pacman -SyyPackage Installation
Section titled “Package Installation”# Install single packagesudo pacman -S package_name
# Install multiple packagessudo pacman -S package1 package2 package3
# Install from specific repositorysudo pacman -S extra/package_namesudo pacman -S core/package_namesudo pacman -S community/package_name
# Install from AUR (using base-devel)sudo pacman -S --needed base-develgit clone aur packagecd packagemakepkg -si
# Reinstall packagesudo pacman -S package_name
# Install from local filesudo pacman -U /path/to/package.pkg.tar.zst
# Download only (no install)sudo pacman -Sw package_namePackage Removal
Section titled “Package Removal”# 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 filessudo pacman -Rns package_name
# Remove package and all packages depending on itsudo pacman -Rc package_name
# Remove orphaned packages (no longer needed)sudo pacman -Rsn $(pacman -Qdtq)
# Remove unused packages (orphans)sudo pacman -Sc # Clean cachePackage Queries
Section titled “Package Queries”# List all installed packagespacman -Q
# List explicitly installed packagespacman -Qe
# List native packages (from core/extra/community)pacman -Qn
# List foreign packages (AUR)pacman -Qm
# Search for packagepacman -Ss keywordpacman -Ss "^package-name"
# Search installed packagespacman -Qs keyword
# Show package infopacman -Qi package_namepacman -Qii package_name # with backup info
# Show package file listpacman -Ql package_name
# Show package dependenciespacman -Si package_name
# Check package files (owned by what)pacman -Qo /path/to/file
# List files not owned by any packagepacman -Qkk # Check allPackage Cache Management
Section titled “Package Cache Management”# Clean cache (remove old packages)sudo pacman -Sc
# Clean all packages from cachesudo pacman -Scc
# List packages in cachels /var/cache/pacman/pkg/
# Keep only latest versionsudo pacman -Sc26.3 pacman Configuration
Section titled “26.3 pacman Configuration”/etc/pacman.conf
Section titled “/etc/pacman.conf”# Main configuration filesudo nano /etc/pacman.conf
# Enable parallel downloadsParallelDownloads = 5
# Enable colorsColor
# Enable verbose package listsVerbosePkgLists
# Enable ILoveCandy (pacman animation)# Add to end of file or uncomment# ILoveCandy
# Enable check space during installationCheckSpace
# Database path (for multiple installations)# DBPath = /var/lib/pacman/
# Cache path# CacheDir = /var/cache/pacman/pkg/
# Log file# LogFile = /var/log/pacman.log
# ArchitectureArchitecture = x86_64# orArchitecture = i686Repository Configuration
Section titled “Repository Configuration”[core]# Core packagesInclude = /etc/pacman.d/mirrorlist
[extra]# Extra packagesInclude = /etc/pacman.d/mirrorlist
[community]# Community packagesInclude = /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/mirrorlistMirror Configuration
Section titled “Mirror Configuration”# Edit mirrorssudo nano /etc/pacman.d/mirrorlist
# Use fastest mirrorsudo pacman -S reflector
# Generate mirrorlistsudo reflector --country US --latest 10 --sort rate --save /etc/pacman.d/mirrorlist
# Rank mirrors by speedsudo pacman -S pacman-contribrankmirrors -6 /etc/pacman.d/mirrorlist
# Uncomment all mirrors (select all)# In vim: :%s/^#//26.4 Package Signing and Security
Section titled “26.4 Package Signing and Security”Signature Verification
Section titled “Signature Verification”# Check package signaturepacman -Qi package_name | grep Signature
# List trusted keyspacman-key --list-keys
# Refresh keyssudo pacman-key --refresh-keys
# Add keysudo pacman-key --recv-keys keyid
# Sign keysudo pacman-key --lsign keyid
# Verify databasesudo pacman -Sy --verify
# Disable signature checking (NOT RECOMMENDED)# In /etc/pacman.conf:# SigLevel = Never26.5 Hooks
Section titled “26.5 Hooks”Creating Hooks
Section titled “Creating Hooks”# Hook directoryls /usr/lib/alpm/hooks/
# User hookssudo mkdir -p /etc/pacman.d/hooks
# Example: Update grub after kernel upgrade# /etc/pacman.d/hooks/50-update-grub.hook[Trigger]Type = PackageOperation = UpgradeTarget = linux
[Action]Description = Updating GRUB for new kernel...When = PostTransactionExec = /usr/bin/grub-mkconfig -o /boot/grub/grub.cfgCommon Hooks
Section titled “Common Hooks”# Rebuild initramfs after kernel upgrade[Trigger]Type = PackageOperation = UpgradeTarget = linux
[Action]Description = Rebuilding initramfs...When = PostTransactionExec = /usr/bin/mkinitcpio -P
# Update systemd units[Trigger]Type = PackageOperation = InstallOperation = UpgradeTarget = systemd
[Action]Description = Reloading systemd daemon...When = PostTransactionExec = /usr/bin/systemctl daemon-reload26.6 AUR (Arch User Repository)
Section titled “26.6 AUR (Arch User Repository)”AUR Helpers
Section titled “AUR Helpers”# Install base-devel (needed for building AUR packages)sudo pacman -S --needed base-devel
# Using yay (most popular AUR helper)# Install yaygit clone https://aur.archlinux.org/yay.gitcd yaymakepkg -si
# Common yay commandsyay -Syu # Update system + AURyay -Ss keyword # Searchyay -S package # Installyay -Rsc package # Remove with depsyay -Yc # Clean unused depsyay -Ycc # Clean all cache
# Using paru (Rust-based alternative)git clone https://aur.archlinux.org/paru.gitcd parumakepkg -si
# Using pamac (GUI)sudo pacman -S pamac
# Using aurutilssudo pacman -S aurutilsManual AUR Installation
Section titled “Manual AUR Installation”# Clone packagegit clone https://aur.archlinux.org/package_name.gitcd package_name
# Review PKGBUILDcat PKGBUILDnano PKGBUILD
# Build and installmakepkg -si
# Or just buildmakepkg -s
# Install local packagesudo pacman -U *.pkg.tar.zst26.7 Troubleshooting
Section titled “26.7 Troubleshooting”Common Issues
Section titled “Common Issues”# Fix "target not found"sudo pacman -Syyu
# Fix "package not found" in syncsudo pacman -Syy && sudo pacman -S package
# Fix "could not resolve host"# Check DNSping archlinux.org# Edit /etc/resolv.conf if needed
# Fix "invalid or corrupted package"sudo pacman -Sccsudo pacman -Syu
# Fix "conflicting files"# Overwritesudo pacman -S --overwrite "*" package
# Fix dependency issuessudo pacman -Syu --debug
# Recover from failed update# Boot from Arch ISO# Mount filesystem# pacman -Syu --root /mnt
# Check for conflictspacman -QkkSystem Recovery
Section titled “System Recovery”# Reinstall all packagessudo pacman -S $(pacman -Qq | grep -v "$(pacman -Qmq)")
# Restore pacman database# From backupsudo cp /var/lib/pacman/local/*.tar.zst backup/
# Or use arch-chrootsudo arch-chroot /mntpacman -Syu26.8 Interview Questions
Section titled “26.8 Interview Questions”Basic Questions
Section titled “Basic Questions”-
What is pacman?
- Official package manager for Arch Linux
-
How do you update the system?
sudo pacman -Syu
-
What is the difference between -S and -U?
- -S installs from repository; -U installs from local file
-
What is AUR?
- Arch User Repository - community-maintained packages
-
How do you remove orphaned packages?
sudo pacman -Rsn $(pacman -Qdtq)
Intermediate Questions
Section titled “Intermediate Questions”-
What is the rolling release model?
- Continuous updates without major version jumps
-
How do hooks work in pacman?
- Trigger actions on package operations
-
What is libalpm?
- Backend library for pacman
-
How do you verify package signatures?
- pacman-key management
-
What are hooks vs scripts in PKGBUILD?
- Hooks are system-level, scripts are package-specific
Summary
Section titled “Summary” 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) | || +----------------------------------------------------------+ || |+------------------------------------------------------------------+