1. Introduction to Pacman and the Arch Way
What is Pacman? pacman
is the uniquely named Package **Man**ager for Arch Linux. It's a powerful, yet relatively simple, command-line utility responsible for installing, upgrading, removing, and otherwise managing software packages on an Arch system. It works with binary packages (pre-compiled software) typically in the .pkg.tar.zst
(or older .pkg.tar.xz
) format. pacman
is known for its speed and straightforward dependency resolution.
The Arch Linux Philosophy and Pacman: pacman
and its usage are heavily influenced by the core principles of Arch Linux: Simplicity (KISS), User-centricity, and Rolling Release. pacman
aims for a simple command structure and expects the user to understand the implications of their commands.
Distributions Using Pacman: Arch Linux is the primary distribution. Arch-based derivatives like Manjaro, EndeavourOS, and Artix Linux also use pacman
, though they might add their own tools or wrappers.
Repositories: pacman
downloads packages from software repositories defined in /etc/pacman.conf
. Key official repositories include core
, extra
, and multilib
. The /etc/pacman.d/mirrorlist
file specifies the mirror servers.
2. Synchronizing Repositories and Upgrading the System
sudo pacman -Sy
Synchronizes local package databases with mirrors.
Action: This command Synchronizes the local package databases with the master package databases on the mirror servers. It downloads fresh copies of the package lists from all enabled repositories. It does *not* upgrade any packages.
Why: Essential before installing new packages to ensure pacman
knows about the latest available versions. (Note: Using -Sy
alone before installing a single package is generally discouraged; prefer -Syu
).
Example:
sudo pacman -Sy
sudo pacman -Syy
Forces a refresh of all local package databases.
Action: This command Synchronizes and forces a refresh of *all* local package databases, even if pacman
thinks they are already up-to-date. The double y
ensures that fresh copies are downloaded regardless of their apparent freshness.
Why: Useful if you suspect your local databases might be corrupted, if you've recently changed mirrors, or if you want to be absolutely sure you have the latest lists.
Example:
sudo pacman -Syy
sudo pacman -Syu
Synchronizes databases and upgrades all installed packages.
Action: This is the standard and recommended command for a full system update. It performs two actions: 1. -Sy
: **S**ynchronizes the local package databases. 2. -u
: **u**pgrades all currently installed packages on your system that are out of date.
Why: Keeps your entire Arch Linux system current. Due to the rolling release nature of Arch, this command should be run regularly.
Example:
sudo pacman -Syu
pacman
will list all packages to be upgraded and ask for confirmation.
sudo pacman -Syyu
Forces database refresh and full system upgrade.
Action: This combines forcing a full database refresh (-Syy
) with a full system upgrade (-u
).
Why: For a very thorough update, ensuring that your package databases are definitely fresh before upgrading. Useful if -Syu
runs into issues or after significant system changes.
Example:
sudo pacman -Syyu
Partial Upgrades (Discouraged)
Why partial upgrades are not recommended.
Concept: A "partial upgrade" occurs if you synchronize package databases (e.g., sudo pacman -Sy
) and then install a new package (sudo pacman -S <package>
) *without* first upgrading your entire system (-u
). This can lead to an unstable system because the newly installed package might be built against newer versions of libraries than what you currently have installed.
Why Discouraged: Arch Linux does not support partial upgrades. Always try to run sudo pacman -Syu
to update your whole system rather than just syncing and installing one package. If you must install a package after syncing but can't do a full -Syu
immediately, understand the risks involved.
3. Searching for Packages
pacman -Ss <search_term>
Searches synchronized package databases.
Action: **S**earches the synchronized package databases (both package names and their descriptions) for packages that match the given search_term
. The search is case-insensitive and supports regular expressions.
Why: The primary way to find available packages in the repositories.
Example:
pacman -Ss "web browser"
pacman -Ss virtualbox
pacman -Si <package_name>
Displays detailed info about a repository package.
Action: Displays detailed **i**nformation about a specific package that is available in the repositories (but not necessarily installed). This includes its name, version, description, architecture, dependencies, optional dependencies, package size, download size, and the repository it belongs to.
Why: To get comprehensive details about a package before deciding to install it.
Example:
pacman -Si python
pacman -Qi <package_name>
Displays detailed info about an installed package.
Action: Displays detailed **i**nformation about a package that is currently **i**nstalled on your system. This includes its version, description, install date, reason for installation (explicitly installed or as a dependency), dependencies, and more.
Why: To check the version, install reason, and other details of software already on your system.
Example:
pacman -Qi systemd
pacman -Ql <package_name>
Lists all files owned by an installed package.
Action: **L**ists all the files that are owned by the specified *installed* package. It shows the full path for each file.
Why: Useful for seeing exactly where a package has installed its files, or for troubleshooting.
Example:
pacman -Ql nano
pacman -Qo <file_path>
Queries which installed package owns a specific file.
Action: **Q**ueries the package database to determine which installed package **o**wns the specified file.
Why: Helps you identify which package a particular file on your system belongs to.
Example:
pacman -Qo /usr/bin/bash
pacman -Qo /etc/fstab
4. Installing Packages
sudo pacman -S <package_name>
Installs or upgrades specified package(s) from repositories.
Action: This is the main command to **S**ynchronize (install or upgrade) one or more specified packages from the repositories. If the package is not installed, it will be installed along with its dependencies. If already installed but an older version, it will be upgraded. If already installed and up-to-date, pacman
will typically ask if you want to reinstall it.
Why: The primary way to add new software or update specific packages (though -Syu
is preferred for general system updates).
Example:
sudo pacman -S firefox # Installs or upgrades Firefox
Installing Multiple Packages:
sudo pacman -S inkscape gimp krita
pacman
will list all packages to be installed/upgraded (including dependencies) and ask for confirmation.
sudo pacman -U <path_to_package_file.pkg.tar.zst>
Installs a package from a local file or URL.
Action: Installs a package from a local .pkg.tar.zst
(or older .pkg.tar.xz
) file, or directly from a URL. The -U
stands for "Upgrade" but is used for local/remote file installation. pacman
will still attempt to resolve and install dependencies for this package from your synchronized repositories.
Why: For installing packages downloaded manually (e.g., from the AUR before building, or a self-compiled package), or for downgrading if you have an older package file.
Example:
sudo pacman -U ~/Downloads/custom-package-1.2.3-1-x86_64.pkg.tar.zst
sudo pacman -U http://example.com/some-package.pkg.tar.zst
5. Removing Packages
sudo pacman -R <package_name>
Removes the specified package.
Action: **R**emoves the specified package. By default, this does *not* remove its dependencies, even if they are no longer required by any other package. It also keeps configuration files.
Why: To uninstall a specific piece of software.
Example:
sudo pacman -R anjuta
sudo pacman -Rs <package_name>
Removes package and its unneeded dependencies.
Action: **R**emoves the specified package and also recursively removes its dependencies (s
), provided those dependencies are not required by any other installed package and were not explicitly installed by the user.
Why: A more thorough way to remove a package and its unneeded dependencies, helping to keep the system clean.
Example:
sudo pacman -Rs anjuta
sudo pacman -Rsn <package_name>
Complete removal: package, dependencies, and config files.
Action: This is often the most comprehensive way to remove a package. -R
: Removes package. -s
: Removes unneeded dependencies. -n
: ("nosave") Prevents pacman
from saving important configuration files with a .pacsave
extension; instead, these system-wide configuration files are removed directly.
Why: For a complete removal of a package, its unneeded dependencies, and its system-wide configuration files.
Example:
sudo pacman -Rsn anjuta
sudo pacman -Rdd <package_name>
Removes package, ignoring dependency checks (DANGEROUS).
Action: **R**emoves the specified package while ignoring all dependency checks (double d
).
Why: **Use with extreme caution!** This can easily lead to a broken system if you remove a package that other critical parts of your system depend on. It's typically only used in very specific troubleshooting scenarios.
Example (Use with extreme caution!):
# sudo pacman -Rdd problematic_package_if_you_are_sure
6. Managing Package Cache and Orphans
pacman -Qdt
Identifies orphaned packages (dependencies no longer needed).
Action: **Q**ueries the local package database for packages that were installed as a **d**ependency but are no longer required by any other installed package. The t
limits the output to "true" orphans (those not explicitly installed).
Why: Helps you identify packages that can likely be removed to free up disk space and keep your system tidy.
Example:
pacman -Qdt
Use pacman -Qdtq
for a quiet version that only outputs package names, useful for scripting.
sudo pacman -Rns $(pacman -Qdtq)
Removes all identified orphaned packages.
Action: This command combines pacman -Qdtq
(to list orphans quietly) with sudo pacman -Rns
(to remove them, their unneeded dependencies, and system-wide configs). The $()
is command substitution.
Why: Keeps your system clean and efficient by removing unnecessary software.
Example:
sudo pacman -Rns $(pacman -Qdtq)
If no orphans are found, the command does nothing harmful.
sudo pacman -Sc
Cleans cache: removes uninstalled and old versions.
Action: Cleans the package cache (/var/cache/pacman/pkg/
) by removing all cached versions of packages that are no longer installed, and all older cached versions of currently installed packages. It keeps only the currently installed version in the cache.
Why: Frees up disk space while keeping currently installed versions cached for potential downgrades or reinstallations.
Example:
sudo pacman -Sc
pacman
will list packages to be removed from cache and ask for confirmation.
sudo pacman -Scc
Clears the entire package cache (aggressive).
Action: Clears the *entire* package cache (/var/cache/pacman/pkg/
). It removes all downloaded package files, regardless of whether they are for installed packages or not. The double c
is more aggressive.
Why: Frees up the maximum amount of disk space from the package cache. If you need to reinstall or downgrade any package, pacman
will have to download the package file again.
Example:
sudo pacman -Scc
You will be prompted twice for confirmation due to the aggressive nature of this command.
7. The Arch User Repository (AUR) and Helpers
AUR (Arch User Repository)
Community-driven repository with PKGBUILDs.
What is the AUR? The Arch **U**ser **R**epository is a vast community-driven repository for Arch users. It contains package descriptions called **PKGBUILDs**. A PKGBUILD is a shell script with instructions to build a package from source or repackage binaries, then install it using pacman
. Packages are user-submitted and not officially supported by Arch Linux; use them at your own risk after inspecting the PKGBUILD.
makepkg -si
Tool to build packages from PKGBUILDs.
Action: makepkg
is the official Arch Linux tool to build packages from a PKGBUILD. When you download the files for an AUR package (usually by cloning its git repository), you navigate into its directory and run makepkg
.
Common Usage:
makepkg -s
: Automatically resolves and installs build dependencies usingpacman
.makepkg -i
: Installs the built package usingsudo pacman -U
.makepkg -si
: A common combination to sync dependencies, build, and then install.makepkg -c
: Cleans up leftover build files.
Example (inside the directory of a PKGBUILD):
makepkg -si
AUR Helpers (e.g., yay, paru)
Tools to automate AUR package management.
What are they? AUR helpers are command-line tools created by the community to automate searching, downloading, building, and installing/updating packages from the AUR. They greatly simplify AUR usage and often wrap pacman
commands for official repository operations too.
Popular Helpers: yay
and paru
are well-regarded examples.
Example (using yay
syntax, similar for paru
):
yay -S <aur_package_name>
: Installs/updates an AUR package.yay
oryay -Syu
: Updates all official and AUR packages.yay -Ss <search_term>
: Searches official repos and AUR.
Note: AUR helpers themselves often need to be installed manually from the AUR first (e.g., by cloning their git repository and using makepkg -si
).
8. Tips and Best Practices for Arch Linux
- Update Frequently: Due to the rolling release model, run
sudo pacman -Syu
regularly (e.g., daily or weekly) to avoid major upgrade issues. - Read Arch News: Before major updates, check the Arch Linux homepage (archlinux.org) for any news items that might require manual intervention.
- Handle
.pacnew
/.pacsave
Files: Whenpacman
updates a package with a configuration file you may have modified, it might create a.pacnew
(new default config) or.pacsave
(your old config) file. You need to manually review and merge these. Tools likepacdiff
can help. - Avoid Partial Upgrades: Never run
sudo pacman -Sy
followed bysudo pacman -S <package_name>
without a full system upgrade (-Syu
). Always keep your system fully synchronized. - System Maintenance: Regularly clean the cache (
sudo pacman -Sc
or-Scc
) and remove orphans (sudo pacman -Rns $(pacman -Qdtq)
). - The Arch Wiki is Your Friend: The Arch Wiki (wiki.archlinux.org) is an unparalleled resource for documentation on Arch Linux,
pacman
, troubleshooting, and almost everything else.
9. Conclusion
pacman
is a powerful and efficient package manager that reflects Arch Linux's core principles of simplicity and user control. Understanding its operations for synchronizing, upgrading, installing, and removing packages, along with adhering to Arch Linux best practices, is key to maintaining a stable and up-to-date system. The AUR further extends Arch's capabilities, offering a vast selection of community-maintained software for those willing to manage it.