Pacman Package Manager Cheatsheet for Arch Linux
Pacman is the powerful package manager for Arch Linux and its derivatives. This comprehensive guide covers essential commands, advanced operations, and troubleshooting techniques to help you effectively manage your Arch Linux system.
Package Installation
Basic Installation
# Install a single package
sudo pacman -S package-name
# Install multiple packages
sudo pacman -S package1 package2 package3
# Install package without prompting for confirmation
sudo pacman -S --noconfirm package-name
# Install only if not already installed
sudo pacman -S --needed package-nameInstallation from Files
# Install from local package file
sudo pacman -U /path/to/package.pkg.tar.xz
# Install from URL
sudo pacman -U https://example.com/package.pkg.tar.xz
# Install packages from CD/DVD/USB
sudo pacman -U file:///mnt/cdrom/package.pkg.tar.xzPackage Removal
Standard Removal
# Remove a package
sudo pacman -R package-name
# Remove package and its dependencies (not required by other packages)
sudo pacman -Rs package-name
# Remove package, dependencies, and configuration files
sudo pacman -Rns package-name
# Remove package and all packages that depend on it
sudo pacman -Rc package-nameCleanup Operations
# Remove all orphaned packages
sudo pacman -Rs $(pacman -Qtdq)
# Remove package cache (free up disk space)
sudo pacman -Sc
# Remove all cached packages
sudo pacman -SccSystem Updates
Standard Updates
# Update package database
sudo pacman -Sy
# Update all packages
sudo pacman -Su
# Update database and upgrade system (recommended)
sudo pacman -Syu
# Force refresh of package databases
sudo pacman -Syy
# Update with dependency resolution
sudo pacman -Syu --neededPartial Updates (Use with Caution)
# Update specific package
sudo pacman -S package-name
# Downgrade package (requires package cache)
sudo pacman -U /var/cache/pacman/pkg/package-old-version.pkg.tar.xzPackage Information and Search
Search Operations
# Search for packages in repositories
pacman -Ss search-term
# Search for packages with detailed information
pacman -Ss search-term | grep -A 5 -B 5 "search-term"
# Search installed packages
pacman -Qs search-term
# Search package files
pacman -Fl search-termPackage Information
# Show package information
pacman -Si package-name
# Show information for installed package
pacman -Qi package-name
# List files owned by package
pacman -Ql package-name
# Find which package owns a file
pacman -Qo /path/to/file
# Show package dependencies
pacman -Qi package-name | grep "Depends On"
# Show packages that depend on this package
pacman -Qii package-namePackage Listing
Installed Packages
# List all installed packages
pacman -Q
# List explicitly installed packages
pacman -Qe
# List packages installed as dependencies
pacman -Qd
# List orphaned packages
pacman -Qdt
# List foreign packages (from AUR)
pacman -Qm
# List native packages (from official repos)
pacman -QnRepository Packages
# List all packages in repository
pacman -Sl
# List packages from specific repository
pacman -Sl core
# List installed packages from specific repository
pacman -Sl core | grep installedGPG Key Management
List and Verify Keys
# List all trusted GPG keys
pacman-key --list-keys
# List key fingerprints
pacman-key --list-sigs
# Check key signatures
pacman-key --check-sigsAdd and Trust Keys
# Add a GPG key from file
sudo pacman-key --add /path/to/key.asc
# Add key from keyserver
sudo pacman-key --recv-keys KEY-ID
# Trust a key locally
sudo pacman-key --lsign-key KEY-ID
# Trust a key globally
sudo pacman-key --sign-key KEY-IDFor comprehensive GPG key management beyond pacman operations, see the GPG operations cheatsheet, which covers key generation, import/export, and digital signature workflows essential for package repository creation and maintenance.
Key Management
# Initialize keyring
sudo pacman-key --init
# Populate keyring with Arch Linux keys
sudo pacman-key --populate archlinux
# Refresh keys from keyserver
sudo pacman-key --refresh-keys
# Remove a key
sudo pacman-key --delete KEY-IDPackage Download and Caching
Download Operations
# Download packages without installing
mkdir packages blankdb
sudo pacman -Syw --cachedir packages --dbpath blankdb --needed --noconfirm package-name
# Download specific package version
sudo pacman -Syw --cachedir packages --dbpath blankdb package-name=version
# Download with all dependencies
sudo pacman -Syw --cachedir packages --dbpath blankdb --needed --noconfirm package-nameCache Management
# Show cache directory
pacman -v
# List cached packages
ls /var/cache/pacman/pkg/
# Clean cache (keep 3 most recent versions)
sudo paccache -r
# Clean cache (keep only 1 version)
sudo paccache -rk1
# Remove all cached packages for uninstalled software
sudo paccache -ruk0Database Operations
Database Maintenance
# Synchronize package databases
sudo pacman -Sy
# Force synchronization
sudo pacman -Syy
# Check database integrity
sudo pacman -Dk
# Rebuild package database
sudo pacman -FyyDatabase Queries
# Search package files database
pacman -Fl package-name
# Find package that provides a file
pacman -F filename
# Update file database
sudo pacman -FyAdvanced Operations
Dependency Management
# Check dependency tree
pactree package-name
# Show reverse dependencies
pactree -r package-name
# Show optional dependencies
pacman -Qi package-name | grep "Optional Deps"
# Install package with optional dependencies
sudo pacman -S package-name --asdeps optional-dep1 optional-dep2Package Groups
# List all package groups
pacman -Sg
# Show packages in a group
pacman -Sg group-name
# Install entire group
sudo pacman -S group-name
# List installed packages from group
pacman -Qg group-nameConfiguration and Logs
# Show pacman configuration
cat /etc/pacman.conf
# View pacman log
sudo tail -f /var/log/pacman.log
# Search pacman log
grep "keyword" /var/log/pacman.log
# Show recent package operations
grep -E "(installed|removed|upgraded)" /var/log/pacman.log | tail -20Troubleshooting Common Issues
Package Conflicts
# Force installation ignoring conflicts
sudo pacman -S --force package-name
# Ignore specific packages during update
sudo pacman -Syu --ignore package-name
# Temporarily ignore package group
sudo pacman -Syu --ignoregroup group-nameBroken Dependencies
# Check for broken dependencies
sudo pacman -Dk
# Reinstall package with dependencies
sudo pacman -S --force package-name
# Download and reinstall package
sudo pacman -Syu --force package-nameDatabase Corruption
# Remove database lock
sudo rm /var/lib/pacman/db.lck
# Rebuild package database
sudo pacman-db-upgrade
# Verify database integrity
sudo pacman -DkMirror Issues
# Test mirror speed
sudo pacman-mirrors --fasttrack
# Update mirror list
sudo pacman-mirrors --country Country-Name
# Manually edit mirrors
sudo nano /etc/pacman.d/mirrorlistPerformance Optimization
Parallel Downloads
Add to /etc/pacman.conf:
ParallelDownloads = 5Colored Output
Add to /etc/pacman.conf:
ColorVerbose Package Lists
Add to /etc/pacman.conf:
VerbosePkgListsDownload Timeout
Add to /etc/pacman.conf:
XferCommand = /usr/bin/curl -L -C - -f -o %o %uUseful Aliases
Add these to your shell configuration:
# System update
alias update='sudo pacman -Syu'
# Install package
alias install='sudo pacman -S'
# Remove package
alias remove='sudo pacman -Rs'
# Search packages
alias search='pacman -Ss'
# List installed packages
alias listpkg='pacman -Q'
# Clean cache
alias cleancache='sudo pacman -Sc'
# Remove orphans
alias removeorphans='sudo pacman -Rs $(pacman -Qtdq)'Security Best Practices
Package Verification
# Always verify package signatures
sudo pacman -S --needed package-name
# Check package integrity before installation
pacman -Qk package-name
# Verify all installed packages
pacman -QkKey Management Security
# Only trust keys from verified sources
sudo pacman-key --lsign-key KEY-ID
# Regularly refresh keys
sudo pacman-key --refresh-keys
# Remove unused keys
sudo pacman-key --delete OLD-KEY-IDSystem Security
# Regular system updates
sudo pacman -Syu
# Monitor security updates
grep -i security /var/log/pacman.log
# Use official repositories only
# Avoid adding untrusted repositoriesEmergency Recovery
Boot from Live USB
# Mount system partition
mount /dev/sdX1 /mnt
# Mount boot partition (if separate)
mount /dev/sdX2 /mnt/boot
# Chroot into system
arch-chroot /mnt
# Fix broken system
pacman -SyuOffline Package Installation
# Download packages on working system
sudo pacman -Syw --cachedir /path/to/usb package-name
# Install from USB on broken system
sudo pacman -U /path/to/usb/package-name.pkg.tar.xzRelated System Setup and Automation
Automated System Configuration
For comprehensive system setup beyond package management, consider these automated utilities:
- Desktop Environment Setup: Complete Hyprland desktop environment installation with over 50 packages, themes, and applications
- Neovim Development Environment: Automated Neovim installation with custom configuration and language server support
These utilities build upon pacman’s package management capabilities to create fully configured development and desktop environments.
Development Environment Integration
The pacman package manager integrates seamlessly with development workflows:
- Package Creation: Use pacman with GPG signing for custom package repositories
- System Updates: Coordinate pacman updates with development environment configurations
- Dependency Management: Leverage pacman’s dependency resolution for development tool chains
Official Documentation
- Pacman - ArchWiki
- Pacman/Tips and tricks - ArchWiki
- Pacman/Package signing - ArchWiki
- Pacman/Rosetta - ArchWiki
References and Resources
- Pactree - Package dependency tree viewer
- Paccache - Package cache management
- Reflector - Mirror management
Community Resources
Questions Answered in This Document
Q: How do I install a package with pacman?
A: Use sudo pacman -S package-name to install a single package, or sudo pacman -S package1 package2 for multiple packages.
Q: What’s the difference between -R, -Rs, and -Rns when removing packages?
A: -R removes only the package, -Rs removes the package and unused dependencies, and -Rns removes the package, dependencies, and configuration files.
Q: How do I update my entire Arch Linux system?
A: Use sudo pacman -Syu to update the package database and upgrade all installed packages to their latest versions.
Q: How can I search for packages in the repositories?
A: Use pacman -Ss search-term to search repository packages, or pacman -Qs search-term to search only installed packages.
Q: How do I clean up orphaned packages?
A: Run sudo pacman -Rs $(pacman -Qtdq) to remove all orphaned packages (packages installed as dependencies but no longer needed).
Q: How do I add and trust a GPG key for package verification?
A: First add the key with sudo pacman-key --add key.asc, then trust it locally with sudo pacman-key --lsign-key KEY-ID. For comprehensive GPG operations, see the GPG cheatsheet.
Q: How can I download packages without installing them?
A: Create directories with mkdir packages blankdb then use sudo pacman -Syw --cachedir packages --dbpath blankdb --needed --noconfirm package-name.
Q: What should I do if pacman says the database is locked?
A: Remove the lock file with sudo rm /var/lib/pacman/db.lck, but only if you’re sure no other pacman process is running.
Q: How do I find which package owns a specific file?
A: Use pacman -Qo /path/to/file to find which installed package owns a specific file on your system.
Q: How can I see what files a package contains?
A: Use pacman -Ql package-name to list all files owned by an installed package, or pacman -Fl package-name for repository packages.