Table of Contents
Understanding Pacman on Arch-Based Systems
pacman is the package manager used on Arch Linux and most Arch-based distributions (Manjaro, EndeavourOS, etc.). This chapter focuses on basic, everyday usage for beginners on an Arch-like system, not on advanced packaging or repository management.
Throughout, you’ll typically run pacman with sudo on a regular desktop system.
Basic Syntax and Important Options
The general format:
pacman -S— sync (install) packages from repositoriespacman -R— remove packagespacman -Q— query installed packages / local databasepacman -U— install a package file (.pkg.tar.zst, etc.)pacman -Sy,pacman -Syu— sync package databases / upgrade system
pacman uses short, combined options a lot. For example:
pacman -Syu=-S(sync) +-y(refresh databases) +-u(upgrade)
You’ll see the following flags frequently:
-S— sync/install-R— remove-Q— query-U— install from file-s— search-i— show info-y— refresh repository databases-u— upgrade-n— only from “native” (official) repositories-c— clean cache-t— targets only explicitly installed or only dependencies (with other flags)
Updating Package Databases and the System
On Arch, updating is done with pacman directly (there’s no separate “distribution upgrade” command).
Refreshing the Package Databases
To refresh the list of available packages:
sudo pacman -SyThis updates the databases but does not upgrade installed packages.
Full System Upgrade
On Arch, the normal way to update is a full system upgrade:
sudo pacman -SyuThis command:
- Refreshes package databases (
-y) - Upgrades all installed packages to the latest versions (
-u)
On Arch, partial upgrades (updating only some packages) are discouraged; -Syu should be run to keep the system consistent.
Searching for Packages
To search in the official repositories:
pacman -Ss keywordExamples:
pacman -Ss firefox— search for “firefox”pacman -Ss audio player— search for packages with both words in name/description
To search locally installed packages:
pacman -Qs keywordFor example:
pacman -Qs ssh— find installed packages related to SSH
Installing Packages
To install a package from the official repositories:
sudo pacman -S package_nameExamples:
sudo pacman -S firefoxsudo pacman -S neovim
To install multiple packages at once:
sudo pacman -S package1 package2 package3
If packages are provided by different repositories, pacman chooses the one with the highest priority according to your pacman.conf (already set up on most systems).
Reinstalling Packages
If you need to reinstall a package that’s already installed:
sudo pacman -S package_name
pacman will detect that it is already installed and ask whether to reinstall.
You can also force a reinstall:
sudo pacman -S package_name --needed
--needed tells pacman not to reinstall if the latest version is already installed.
Removing Packages
To remove a package, but keep its dependencies (if other things use them):
sudo pacman -R package_nameTo remove a package and dependencies that are no longer needed (i.e., installed as dependencies and not required by anything else):
sudo pacman -Rs package_name
The -s here stands for “recursive removal of unused dependencies” (but pacman will show you what it’s going to remove and ask for confirmation).
To remove a package and its configuration files in /etc (back up if needed!) you might use:
sudo pacman -Rns package_nameFlags:
-n— also remove backup configuration files-s— remove unused dependencies
Be cautious with -Rns on critical packages; always read the list of packages to be removed.
Querying Installed Packages
Some common queries:
List All Installed Packages
pacman -Q
This can be long; you can pipe it to tools like less or grep:
pacman -Q | less
pacman -Q | grep firefoxCheck if a Package Is Installed
pacman -Q package_nameIf the package is not installed, you’ll get an error.
Get Information About an Installed Package
pacman -Qi package_nameThis shows version, install date, description, dependencies, etc.
Get Information About a Package in the Repositories
Even if not installed:
pacman -Si package_nameThis shows what you would be installing, including repository, size, and dependencies.
List Files Installed by a Package
Useful for finding where something was installed:
pacman -Ql package_nameFind Which Package Owns a File
For a file already on your system:
pacman -Qo /path/to/fileFor example:
pacman -Qo /usr/bin/sshThis tells you which installed package provided that file.
Handling the Package Cache
pacman stores downloaded package files in a cache, usually /var/cache/pacman/pkg/. Over time, this can grow large.
View Cache Location
It’s defined in /etc/pacman.conf under the CacheDir configuration, typically:
CacheDir = /var/cache/pacman/pkg/Cleaning the Cache
To remove unused packages from the cache, leaving only the most recent versions of installed packages:
sudo pacman -ScTo remove all cached packages (more aggressive):
sudo pacman -Scc
Use -Scc carefully; it removes everything, so you will need to re-download packages if you downgrade or reinstall.
Installing Local Package Files with pacman -U
Sometimes you have a package file (.pkg.tar.zst or similar) on your system, for example:
- A manually downloaded package from an official source
- A package built with local tools
To install it:
sudo pacman -U /path/to/package.pkg.tar.zst
-U means “upgrade or install from a file”. pacman still resolves dependencies from repositories where possible.
This is different from the Arch User Repository (AUR) helpers, which are separate tools; pacman itself only works with official repositories and local package files.
Working with Orphans and Explicitly Installed Packages
On Arch, packages can be:
- Explicitly installed (you requested them)
- Installed as dependencies of those packages
List Explicitly Installed Packages
pacman -QeThis shows packages you explicitly installed (or that came as part of base groups).
List Orphaned Packages
“Orphans” are packages installed as dependencies that are no longer required by any installed package.
pacman -Qdt-d— only dependency packages-t— unrequired (orphans)
You can remove orphans with:
sudo pacman -Rns $(pacman -Qdtq)Here:
-qmakespacman -Qdtoutput only package names$(...)feeds that list topacman -Rns
Always check the list before confirming removal.
Handling Common pacman Issues (Beginner-Level)
You will often see:
“Database Is Locked”
If you see something like:
error: failed to init transaction (unable to lock database)
if you're sure a package manager is not already running, remove /var/lib/pacman/db.lck
Usually, this means another pacman instance or a GUI updater is running.
Steps:
- Check if
pacmanis running:
ps aux | grep pacman- If nothing is running and you are sure an update is not in progress, you can remove the lock:
sudo rm /var/lib/pacman/db.lck
Then rerun your pacman command.
Conflicting Files
Sometimes you see:
error: failed to commit transaction (conflicting files)
file /path/file already exists in filesystemThis usually means a file from the new package would overwrite an existing file. As a beginner, the safest steps are:
- Read the error carefully to identify the file.
- Search online with the error message and package name.
- Only remove or move files if a trusted solution suggests it.
Avoid forcing overwrites with options you don’t fully understand (--overwrite), unless guided by reliable documentation.
pacman Configuration (Light Overview)
The main configuration file is /etc/pacman.conf. As a beginner, you normally don’t need to edit it except for:
- Enabling or disabling specific repositories (like
multilibon pure Arch) - Adding mirrorlists (usually managed via separate tools on Arch)
Any changes should be made with care and usually only by following official or well-reviewed documentation.
Summary of Common pacman Commands
For quick reference:
- Update system:
sudo pacman -Syu - Search in repos:
pacman -Ss keyword - Search installed:
pacman -Qs keyword - Install package:
sudo pacman -S package - Remove package (keep deps):
sudo pacman -R package - Remove package + unused deps:
sudo pacman -Rs package - Info about installed package:
pacman -Qi package - Info from repos:
pacman -Si package - List files of a package:
pacman -Ql package - What owns a file:
pacman -Qo /path/to/file - List orphans:
pacman -Qdt - Clean cache (unused):
sudo pacman -Sc
These commands cover the daily pacman tasks you’ll need on Arch and Arch-based systems.