What it is
pacman is the Arch Linux package manager, used for installing, upgrading, and removing software packages on Arch-based systems.
Installation
pacman is the default package manager for Arch Linux and its derivatives. It is installed automatically when you install an Arch-based distribution.
Core Concepts
- Package: A bundle of files, configuration, and metadata required to run a specific piece of software.
- Repository: A remote server that hosts packages.
pacmansynchronizes with these repositories to find and download packages. - Database:
pacmanmaintains a local database of installed packages and available packages from synchronized repositories. - Sync: The process of downloading the latest package lists from the repositories.
- Target: A package name or a group of packages.
- Group: A collection of related packages that can be installed together (e.g.,
kde-applications). - Dependencies: Packages that another package requires to function correctly.
pacmanautomatically handles installing dependencies. - Conflicts: Packages that cannot be installed at the same time as another package because they would interfere with each other.
- Optional Dependencies: Packages that are not strictly required but provide additional functionality.
- Provides: A capability that a package offers, which other packages might depend on.
- Make dependency: A package required only during the build process of another package.
- Check dependency: A package required to verify the integrity of another package after installation.
Commands / Usage
Synchronizing Package Databases
-
sudo pacman -SySynchronizes the local package database with the remote repositories. This is usually the first step before installing or upgrading packages. -
sudo pacman -SyyForces a refresh of all package databases, even if they appear to be up-to-date. Useful if you suspect the local database is out of sync.
Installing Packages
-
sudo pacman -S firefoxInstalls thefirefoxpackage and its dependencies. -
sudo pacman -SyuSynchronizes the package databases and then upgrades all installed packages to their latest versions. This is the most common command for system updates. -
sudo pacman -SuUpgrades all installed packages to their latest versions without synchronizing the package databases first. (Use with caution,-Syuis preferred). -
sudo pacman -S package1 package2Installs multiple packages at once. -
sudo pacman -S --needed package1Installspackage1only if it is not already installed or if the installed version is older than the one in the repository. -
sudo pacman -S --asdeps package1Installspackage1as an optional dependency. This is typically used by other packages. -
sudo pacman -S --asexplicit package1Markspackage1as explicitly installed, preventing it from being removed as an unneeded dependency later. -
sudo pacman -S --overwrite '<path>' package_nameInstallspackage_nameand allows it to overwrite files at<path>that are managed by other packages. Use with extreme caution. Example:sudo pacman -S --overwrite '/usr/lib/lib*' package_name
Removing Packages
-
sudo pacman -R package_nameRemovespackage_namebut leaves its dependencies installed. -
sudo pacman -Rs package_nameRemovespackage_nameand its dependencies that are not required by any other installed package. -
sudo pacman -Rsc package_nameRemovespackage_name, its dependencies that are not required by any other installed package, and also removes packages that depend onpackage_name. Use with extreme caution. -
sudo pacman -Rsn package_nameRemovespackage_nameand its configuration files. -
sudo pacman -Rns package_nameRemovespackage_name, its dependencies that are not required by any other installed package, and its configuration files. -
sudo pacman -Rdd package_nameRemovespackage_nameand ignores dependency checks. Use with extreme caution, as this can break your system.
Querying Packages
-
pacman -QLists all installed packages. -
pacman -Q package_nameChecks ifpackage_nameis installed and shows its version. -
pacman -Qs keywordSearches installed packages forkeyword. -
pacman -Qi package_nameDisplays detailed information about an installed package. -
pacman -Ql package_nameLists all files owned by an installedpackage_name. -
pacman -Qo /path/to/fileFinds which installed package owns the specified file. -
pacman -QmLists installed packages that were not found in the sync databases (e.g., manually compiled packages). -
pacman -QeLists explicitly installed packages. -
pacman -QdLists packages installed as dependencies. -
pacman -QcLists packages that have configuration files that differ from the installed version. -
pacman -QkChecks the integrity of all installed packages. -
pacman -Qkk package_nameChecks the integrity ofpackage_namemore thoroughly. -
pacman -Ss keywordSearches for packages in the synchronized repositories that matchkeyword. -
pacman -Si package_nameDisplays detailed information about a package available in the repositories. -
pacman -Sl repository_nameLists all packages in a specific repository. Example:pacman -Sl core -
pacman -Sg group_nameLists packages belonging to a specific package group.
Package Groups
sudo pacman -S group_nameInstalls all packages within a specified group. Example:sudo pacman -S gnome
Cleaning the Package Cache
-
sudo pacman -ScRemoves all packages from the cache that are no longer installed. -
sudo pacman -SccRemoves all packages from the cache, including those that are still installed. Use with caution. -
sudo paccache -rRemoves all cached packages except for the three most recent versions of each. (Requirespacman-contribpackage). -
sudo paccache -rk 2Removes all cached packages except for the two most recent versions of each. (Requirespacman-contribpackage).
Other Operations
-
sudo pacman -D --asexplicit package_nameMarkspackage_nameas explicitly installed. -
sudo pacman -D --asdeps package_nameMarkspackage_nameas a dependency. -
sudo pacman -U /path/to/package.pkg.tar.zstInstalls a package from a local file. -
sudo pacman -U /path/to/package1.pkg.tar.zst /path/to/package2.pkg.tar.zstInstalls multiple local packages. -
sudo pacman -F filenameSearches for files in the file database. This requires the file database to be generated and synchronized first. -
sudo pacman -FySynchronizes the file database. -
sudo pacman -FyyForces a refresh of the file database. -
sudo pacman -Syyu --noconfirmSynchronizes databases, upgrades all packages, and automatically confirms all prompts. Use with extreme caution.
Common Patterns
-
Full system upgrade:
sudo pacman -SyuThis is the most frequent command for keeping your Arch system up-to-date. -
Search for a package:
pacman -Ss <search_term>Example:pacman -Ss web browser -
Find which package owns a file:
pacman -Qo /usr/bin/vimUseful when you encounter a file and want to know which package installed it. -
Remove a package and its unneeded dependencies:
sudo pacman -Rs <package_name>Example:sudo pacman -Rs vlc -
Install a package and mark it as explicitly installed:
sudo pacman -S --asexplicit <package_name>This prevents it from being removed if it’s only a dependency of another package you later uninstall. -
Reinstall a package (useful for fixing broken packages):
sudo pacman -S <package_name>This will reinstall the package from the repository, overwriting existing files. -
Clean up old package cache:
sudo paccache -r(Requirespacman-contrib) Keeps the last 3 versions of each package. -
View installed files of a package:
pacman -Ql <package_name>Example:pacman -Ql nano -
Check integrity of installed packages:
sudo pacman -QkFollowed bysudo pacman -Qkkfor a more thorough check if issues are found. -
Install a package from a local .pkg.tar.zst file:
sudo pacman -U ~/Downloads/my_package-1.0-1-x86_64.pkg.tar.zst -
Remove a package and its configuration files:
sudo pacman -Rsn <package_name>Example:sudo pacman -Rsn gnome-tweaks
Gotchas
-
Partial Upgrades: Running
pacman -Sy <package>without-ucan lead to a partially upgraded system if the package you’re installing requires newer libraries than what’s currently installed. Always usesudo pacman -Syufor system-wide upgrades. -
--noconfirm: Using--noconfirmwithpacman -Syuor other modification commands can lead to unintended consequences if you don’t fully understand what’s being changed. It’s best to review prompts and confirm actions manually. -
AUR Helpers:
pacmanitself does not manage packages from the Arch User Repository (AUR). You need an AUR helper (likeyay,paru, etc.) for that. These helpers often usepacmaninternally but have their own syntax. -
Configuration Files (
.pacsave,.pacnew): When upgrading packages that include new or modified configuration files,pacmanmight save your existing configuration as.pacsaveand the new one as.pacnew. It is your responsibility to merge these files if necessary. Tools likemeldordiffcan help. -
Force Overwriting Files: Using
pacman -S --overwriteshould be done with extreme caution. It can break package management if used incorrectly, leading to files being managed by multiple packages or unexpected behavior. -
pacman -Rdd: This command bypasses all dependency checks. It is highly dangerous and can easily render your system unusable. Only use it as a last resort and with full knowledge of the consequences. -
Repository Synchronization: If you have issues installing or updating, the first step is always to ensure your local package database is synchronized (
sudo pacman -Syyu). Sometimes, temporarily adding a mirror to the top of your/etc/pacman.d/mirrorlistcan resolve slow download speeds or connection errors.