pacman Command in Arch Linux: Syntax, Options & Practical Examples

Tested on Arch Linux (rolling 2025)
Package pacman 7.0
Applies to Arch Linux
Privilege sudo or root
Man page pacman(8)
Scope On Arch Linux and derivatives, pacman is the native package manager. It syncs official repositories, installs and removes packages with dependency tracking, and maintains a local package database under /var/lib/pacman/.
Related guides Linux commands

pacman — quick reference

Sync, install, and upgrade (-S)

When to use Command
Full system upgrade (sync + refresh + upgrade) sudo pacman -Syu
Install a package from repos sudo pacman -S package_name
Install only if not already present sudo pacman -S --needed package_name
Install multiple packages sudo pacman -S pkg1 pkg2
Refresh package database only sudo pacman -Sy
Force refresh all mirrors sudo pacman -Syy
Download package without installing sudo pacman -Sw package_name
Install a local .pkg.tar.zst file sudo pacman -U package.pkg.tar.zst

Always prefer -Syu before installing on Arch — partial upgrades break dependencies.

Remove (-R)

When to use Command
Remove a package, keep deps sudo pacman -R package_name
Remove package and unused dependencies sudo pacman -Rs package_name
Remove package, deps, and config files sudo pacman -Rns package_name
Force remove ignoring deps (dangerous) sudo pacman -Rdd package_name

Query installed packages (-Q)

When to use Command
List all installed packages pacman -Q
List explicitly installed (not deps) pacman -Qe
Search installed packages by keyword pacman -Qs keyword
Show installed package details pacman -Qi package_name
List files installed by a package pacman -Ql package_name
Find which package owns a file pacman -Qo /path/to/file
List orphan packages pacman -Qtd
Check package file integrity pacman -Qk package_name

Search repositories (-S query)

When to use Command
Search repos by keyword pacman -Ss keyword
Show repo package details pacman -Si package_name

File database (-F) and database ops (-D)

When to use Command
Refresh file database sudo pacman -Fy
Find which package contains a filename pacman -F filename
Mark package as dependency sudo pacman -D --asdeps package_name
Mark package as explicitly installed sudo pacman -D --asexplicit package_name

Cache maintenance

When to use Command
Remove uninstalled package files from cache sudo pacman -Sc
Remove all cached package files sudo pacman -Scc

Help and version

When to use Command
Show pacman version pacman --version
Show option help pacman -S --help

pacman — command syntax

Synopsis from pacman(8) on Arch Linux:

text
pacman <operation> [options] [targets]

Main operations: -S (sync/install), -R (remove), -Q (query local DB), -U (upgrade local package), -F (file search), -D (database tweak). Configuration: /etc/pacman.conf. Sync databases: /var/lib/pacman/sync/.


pacman — command examples

Essential Full system upgrade (-Syu)

On Arch, always sync the database and upgrade the system before installing new software — partial upgrades cause dependency breakage.

Run the command:

bash
sudo pacman -Syu

Sample output:

output
:: Synchronizing package databases...
 core is up to date
 extra is up to date
 community is up to date
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...

Packages (3) curl-8.8.0-1  openssl-3.3.0-1  pacman-7.0.0-1

Total Download Size:   12.50 MiB
Total Installed Size:  45.00 MiB

:: Proceed with installation? [Y/n] y
...
(3/3) checking keys in keyring                     [----------------------] 100%
(3/3) checking package integrity                   [----------------------] 100%
(3/3) loading package files                        [----------------------] 100%
(3/3) checking for file conflicts                  [----------------------] 100%
(3/3) checking available disk space                [----------------------] 100%
:: Processing package changes...
(1/3) upgrading curl                               [----------------------] 100%
(2/3) upgrading openssl                            [----------------------] 100%
(3/3) upgrading pacman                             [----------------------] 100%
:: Running post-transaction hooks...
(1/1) Restarting accounts daemon...
Essential Install a package from official repos

Install one package after the system is up to date — combine upgrade and install in one transaction when possible.

Run the command:

bash
sudo pacman -Syu htop

Or install without upgrading other packages (only when you already ran -Syu recently):

bash
sudo pacman -S htop

Sample output:

output
resolving dependencies...
looking for conflicting packages...

Packages (1) htop-3.3.0-1

Total Installed Size:  0.45 MiB

:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring                     [----------------------] 100%
(1/1) checking package integrity                   [----------------------] 100%
(1/1) loading package files                        [----------------------] 100%
(1/1) checking for file conflicts                  [----------------------] 100%
(1/1) checking available disk space                [----------------------] 100%
:: Processing package changes...
(1/1) installing htop                              [----------------------] 100%

Verify:

bash
pacman -Qi htop | grep -E '^Name|^Version|^Installed Size'

Sample output:

output
Name            : htop
Version         : 3.3.0-1
Installed Size  : 450.00 KiB
Essential Remove a package and unneeded dependencies

Remove software and cascade-delete dependencies nothing else needs.

Run the command:

bash
sudo pacman -Rns htop

Sample output:

output
checking dependencies...

Packages (1) htop-3.3.0-1

Total Removed Size:  0.45 MiB

:: Do you want to remove these packages? [Y/n] y
(1/1) removing htop                                [----------------------] 100%
Common Search repositories before installing

Find the exact package name in official repos — search matches name and description.

Run the commands:

bash
pacman -Ss nginx
pacman -Si nginx

Sample output:

output
extra/nginx 1.26.0-1
    Lightweight HTTP server and IMAP/POP3 proxy server
...
Name            : nginx
Repository      : extra
Version         : 1.26.0-1
Description     : Lightweight HTTP server and IMAP/POP3 proxy server
Architecture    : x86_64
URL             : https://nginx.org/
Licenses        : BSD-2-Clause
Groups          : None
Provides        : None
Depends On      : openssl  pcre  zlib  geoip  libxml2
Optional For    : None
Conflicts With  : None
Replaces        : None
Download Size   : 520.00 KiB
Installed Size  : 1.50 MiB
Common Find which package owns a file

Trace an unexpected binary or config file back to its package — useful after manual edits or security audits.

Run the commands:

bash
pacman -Qo /usr/bin/bash
pacman -Ql pacman | head -5

Sample output:

output
/usr/bin/bash is owned by bash 5.2.15-1
pacman /usr/
pacman /usr/bin/
pacman /usr/bin/pacman
pacman /usr/share/
pacman /usr/share/man/
Common Remove orphan packages

After uninstalling meta-packages, leftover dependencies clutter the system — remove orphans safely.

Run the commands:

bash
pacman -Qtd
pacman -Qtdq | sudo pacman -Rns -

Sample output:

output
orphan1 1.0-1
orphan2 2.0-1
...
checking dependencies...
:: Do you want to remove these packages? [Y/n] y
Advanced Install or downgrade from a local package file

Install a vendor RPM-style drop-in or roll back using a file still in the cache.

Run the command:

bash
sudo pacman -U /var/cache/pacman/pkg/nginx-1.24.0-1-x86_64.pkg.tar.zst

Sample output:

output
loading packages...
resolving dependencies...
looking for conflicting packages...

Packages (1) nginx-1.24.0-1

Total Installed Size:  1.40 MiB
Net Upgrade Size:      -0.10 MiB

:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring                     [----------------------] 100%
...
downgrading nginx                                  [----------------------] 100%

Downgrades may require --overwrite '*' when file conflicts appear — use only when you understand the conflict.

Advanced Search the file database for a missing command

When you know a filename but not the package, refresh -F and search (requires pacman -Fy periodically).

Run the commands:

bash
sudo pacman -Fy
pacman -F useradd

Sample output:

output
:: Updating 5 repos...
  downloading core.db...
core/etc/default/useradd
    core/shadow (4.14.0-1)
usr/bin/useradd
    core/shadow (4.14.0-1)
Advanced Clean package cache

Free disk space under /var/cache/pacman/pkg/-Sc keeps installed versions; -Scc removes everything.

Run the commands:

bash
sudo pacman -Sc
sudo pacman -Scc

Sample output:

output
Cache directory: /var/cache/pacman/pkg/
Packages to keep:
  All locally installed packages

Cache cleanup: 15 packages removed, 120.00 MiB freed
...
Cache directory: /var/cache/pacman/pkg/
...
Cache cleanup: All packages removed, 850.00 MiB freed

After -Scc, offline downgrades need re-downloading from mirrors.


pacman — when to use / when not

Use pacman whenUse something else when
  • You administer Arch Linux or an Arch-based distro
  • You install from official repositories configured in /etc/pacman.conf
  • You follow the rolling release model — regular -Syu
  • You need AUR helpers for community packages — they wrap pacman but AUR builds are separate
  • You are on Debian/Ubuntu — use [apt](/apt-command-in-linux/)
  • You are on RHEL/Fedora — use [dnf](/dnf-command-in-linux/)
  • You want stable point releases without rolling updates — Arch may not fit
  • You only need to build from source with no package — use make/install or containers

pacman vs apt vs dnf

pacman apt dnf
Distro Arch Debian/Ubuntu RHEL/Fedora
Full upgrade pacman -Syu apt update && apt upgrade dnf upgrade
Remove + deps pacman -Rns apt autoremove dnf autoremove
Local package pacman -U file.pkg.tar.zst dpkg -i / apt install ./deb dnf install ./rpm
Partial upgrade risk High — avoid -Sy then install Moderate Moderate

pacman — interview corner

What is pacman in Arch Linux?

pacman is Arch's native package manager. It downloads packages from mirrors listed in /etc/pacman.conf, verifies signatures, installs files tracked in the local package database (/var/lib/pacman/), and handles dependencies for official repos.

Core operations map to letters: -S sync/install, -R remove, -Q query local DB, -U install local package file.

A strong answer is:

"pacman is Arch's package manager — -S install/sync, -R remove, -Q query. It works with official repos in pacman.conf and keeps the local package DB under /var/lib/pacman/."

What does pacman -Syu do?

It runs a full system upgrade in one transaction:

Flag Meaning
-S Sync (install/upgrade from repos)
-y Refresh package databases
-u Upgrade all installed packages

Arch expects regular -Syu — installing with -Sy alone then -S pkg without -u causes partial upgrades and broken dependencies.

A strong answer is:

"-Syu refreshes databases and upgrades all packages together. On Arch I avoid partial upgrades — I run -Syu before installing new software."

What is the difference between pacman -R and -Rns?
Option Removes Also removes
-R The package Nothing else automatically
-Rs Package Dependencies not required by other packages
-Rns Package + deps Config files marked as backup

Use -Rns for normal uninstalls; -Rdd only when you understand dependency breakage.

A strong answer is:

"-R removes the package only. -Rns also removes unneeded dependencies and config files — that's my default uninstall. -Rdd ignores dependencies and is a last resort."

When do you use pacman -Qo vs pacman -F?
Command Needs Answers
pacman -Qo /path File on disk Which installed package owns it
pacman -F name Updated file DB (-Fy) Which repo package contains that path

Use -Qo for audits of the live system; use -F when the file is not installed yet.

A strong answer is:

"-Qo queries the installed system — who owns this file. -F searches repo file lists after pacman -Fy — useful when the command isn't installed yet."

How do you clean orphan packages on Arch?

Orphans are dependencies no longer required by any explicitly installed package:

bash
pacman -Qtd
pacman -Qtdq | sudo pacman -Rns -

Also clear stale cache periodically:

bash
sudo pacman -Sc

A strong answer is:

"I list orphans with pacman -Qtd and remove them with Qtdq piped to pacman -Rns. I also run -Sc to trim /var/cache/pacman/pkg/."


Troubleshooting

Symptom Likely cause What to try
failed to synchronize databases Mirror down or no network Check connectivity; try -Syy; switch mirror in /etc/pacman.d/mirrorlist
pacman: command not found Wrong distro (Debian/Ubuntu, RHEL, …) Install on Arch-based systems; use apt or dnf elsewhere
Partial upgrade / dependency errors Installed without -u after -Sy Full pacman -Syu; never -Sy then install alone
invalid or corrupted package Bad download or keyring pacman -Scc; pacman-key --refresh-keys; retry
database file exists / lock Another pacman running Wait or remove /var/lib/pacman/db.lck if no pacman process
File conflict on upgrade Overwritten local files Read prompt; last resort pacman -Syu --overwrite per file glob

References

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)