Linux/Unix: Arch-Based Package Management β pacman Command Explained with Examples
Introduction β Why Learn pacman in Arch Linux?
Arch-based distributions like Arch Linux, Manjaro, and EndeavourOS use pacman as their primary package manager. Unlike apt or yum, pacman is fast, lightweight, and designed to keep your system simple and bleeding-edge.
In this guide, youβll learn:
- How to install, remove, and update packages using
pacman - How to search and list packages from official and local repositories
- Real-world command usage with options and examples
What is pacman?
pacman is the package manager for Arch Linux and its derivatives. It combines binary package installation with dependency resolution, making it an all-in-one package handling tool.
Syntax:
sudo pacman [options] [package_name]
Essential pacman Commands & Examples
1. Update Package Database and System
sudo pacman -Syu
Output:
:: Synchronizing package databases...
:: Starting full system upgrade...
-S = sync, -y = refresh DB, -u = upgrade system
Always run this before installing packages.
2. Install a Package
sudo pacman -S firefox
Output:
resolving dependencies...
looking for conflicting packages...
Installs Firefox and its required dependencies.
3. Remove a Package
sudo pacman -R firefox
Removes Firefox but keeps dependencies that may be shared.
sudo pacman -Rns firefox
Removes Firefox and its unused dependencies and config files.
4. Search for a Package
pacman -Ss vlc
Output:
extra/vlc 3.0.18-3
Multi-platform MPEG, VCD/DVD, and DivX player
Searches the synchronized package database for a match.
5. List Installed Packages
pacman -Q
Lists all installed packages with versions.
Filter specific package:
pacman -Qs vlc
6. Clean Cache to Free Disk Space
sudo pacman -Sc
Clears outdated packages from the cache (prompted).
To remove all cache (use with caution):
sudo pacman -Scc
7. Fix Broken Packages or Dependencies
sudo pacman -Syu --overwrite '*'
Force overwrite of conflicting files.
To reinstall a package:
sudo pacman -S package-name
Key pacman Flags Cheat Sheet
| Flag | Meaning |
|---|---|
-S | Install package |
-R | Remove package |
-U | Install local .pkg.tar.zst file |
-Ss | Search package in repo |
-Qs | Search installed packages |
-Qdtq | List unused orphaned packages |
-Sc | Clean package cache |
-Syu | Full system update |
Summary β Recap & Next Steps
The pacman command is a versatile and powerful tool for managing packages on Arch-based Linux systems. With just a few flags, you can search, install, update, remove, and clean packages in seconds.
Key Takeaways:
- Use
sudo pacman -Syufor full system updates. - Use
-Rnsto cleanly remove packages. - Use
-Ssand-Qsto search for remote and local packages. - Use
-Scor-Sccto reclaim disk space by cleaning cached files.
FAQs
Can pacman install .deb or .rpm packages?
No. Arch uses its own .pkg.tar.zst format. Use tools like debtap for .deb conversion.
Whatβs the difference between -R and -Rns?
-R removes the package. -Rns removes the package and any unneeded dependencies and configuration files.
How do I install a local .pkg.tar.zst file?
Use:
sudo pacman -U ./package.pkg.tar.zst
Can I rollback a package in pacman?
Not directly. But you can manually download previous versions from the Arch Linux Archive.
How do I remove orphaned packages?
Use:
sudo pacman -Rns $(pacman -Qdtq)
Share Now :
