Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Packages and Services

Linux pacman command

Reference for pacman, the Arch Linux package manager: install, remove, upgrade, query and search packages, understand the -S, -R, -Q and -U operations.

pacman is the package manager of Arch Linux and its derivatives (Manjaro, EndeavourOS and others). It installs, upgrades, removes and queries packages, and it resolves dependencies from the repositories listed in /etc/pacman.conf. Unlike apt, pacman has one command with a set of single-letter operations, and each operation takes its own options.

The operation letter comes first and is always uppercase: -S (sync, meaning repositories), -R (remove), -Q (query the local database), -U (upgrade from a local file), -F (file database) and -D (database). Lowercase letters after it are options, usually combined: -Syu means "sync, refresh, upgrade".

Terminal
pacman -S package          # install
pacman -Syu                # refresh the lists and upgrade the whole system
pacman -Rns package        # remove, with unneeded dependencies and config files
pacman -Qs word            # search installed packages

Try it

The sandbox is not Arch Linux, so pacman itself is not available. Both examples are read-only demonstrations that parse typical pacman output and configuration with ordinary text tools.

Bash Working with pacman -Q style output (sample data)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Reading a pacman.conf (sample file)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
pacman OPERATION [OPTIONS] [TARGETS]
Operation Description
-S pkg Install a package from the repositories, with dependencies.
-Sy Download fresh package lists. Never combine with a partial install; use -Syu.
-Su Upgrade all packages that have newer versions.
-Ss word Search repository packages by name and description.
-Si pkg Show details of a repository package.
-R pkg Remove a package. -Rs also removes unneeded dependencies, -Rn skips saving .pacsave config backups.
-Q List installed packages. -Qs searches them, -Qi shows info, -Ql lists files, -Qo FILE finds the owner of a file.
-Qe, -Qm, -Qdt Explicitly installed, foreign (not in a repository), and orphaned dependencies.
-U file.pkg.tar.zst Install a package from a local file or URL.
-F file Find which package provides a file (after pacman -Fy).
-Sc, -Scc Clean old (or all) cached package files in /var/cache/pacman/pkg.
--noconfirm Do not ask questions; useful in scripts.

Returns: exit status 0 on success and non-zero on failure (a package not found, a conflict, a failed transaction). Almost every operation that changes the system needs root.

Usage notes

  • Never do partial upgrades. Arch is a rolling release. Running pacman -Sy pkg (refresh and install without upgrading) can leave the system with mismatched library versions. Always use pacman -Syu first, or -Syu pkg.
  • Package files live in the cache. Downloaded packages stay in /var/cache/pacman/pkg until you clean them. paccache -r (from pacman-contrib) keeps the last three versions.
  • Orphans: pacman -Qdtq lists packages installed as dependencies that nothing needs anymore; remove them with pacman -Rns $(pacman -Qdtq) (check the list first, and note it is empty on a tidy system).
  • Config changes: when an upgrade finds a modified config file, it writes the new one as file.pacnew; compare and merge it yourself (pacdiff helps).
  • Locks: /var/lib/pacman/db.lck exists while pacman runs. Delete it only when you are sure no pacman process is alive.
  • AUR packages (the Arch User Repository) are not installed by pacman directly. You build them with makepkg or a helper, then install the result with pacman -U.
  • Name queries are exact for -Q; use -Qs for a pattern match and -Ss to search the repositories.
  • Compared with apt: -S is apt install, -Rns is apt purge, -Qo is dpkg -S, -Ql is dpkg -L.