Two-Level Syntax and Common Flags#
The easiest way to remember pacman is as "two levels of syntax":
pacman -<大类><小参数>At the first level, learn the four most common operation groups:
S= Sync: synchronize with repositories / install softwareQ= Query: query software installed locallyR= Remove: uninstallU= Upgrade: install a local package file
These are the essential operations.
| Command | Meaning | Memory aid |
|---|---|---|
pacman -S 包名 |
Install software | S = Sync/install |
pacman -Syu |
Upgrade the entire system | y = refresh, u = upgrade |
pacman -Ss 关键词 |
Search repositories | The second s = search |
pacman -Si 包名 |
View details of a repository package | i = info |
pacman -Qs 关键词 |
Search installed software | Q = local Query + s = search |
pacman -Qi 包名 |
View details of an installed package | i = info |
pacman -Ql 包名 |
List the files installed by a package | l = list |
pacman -Qo /路径/文件 |
Find which package owns a file | o = owner |
pacman -R 包名 |
Uninstall | R = Remove |
pacman -Rs 包名 |
Uninstall along with dependencies that are no longer needed | s = recursive deps |
pacman -Rns 包名 |
Uninstall along with dependencies that are no longer needed, without saving managed configuration files as .pacsave | n = nosave |
pacman -U xxx.pkg.tar.zst |
Install a local package | U = Upgrade file |
pacman -Sc |
Clean old cached packages | c = clean |
Your most frequent everyday commands can be reduced to:
sudo pacman -Syu
sudo pacman -S foo
pacman -Ss foo
pacman -Qs foo
pacman -Qi foo
pacman -Ql foo
pacman -Qo /usr/bin/foo
sudo pacman -Rns fooThe most important distinction to understand is between S and Q:
-S* → 问“仓库里有什么”
-Q* → 问“我电脑上已经有什么”So:
pacman -Ss firefox= Search remote repositories for firefox.
pacman -Qs firefox= Search the firefox-related packages already installed locally.
A Few Easily Confused Commands
pacman -SyThis only refreshes the database, without upgrading packages. Generally, avoid doing this by itself on Arch, as it can cause a partial upgrade.
Normally, use:
sudo pacman -SyuOne way to memorize it is:
S = Sync
y = refresh repository database
u = upgrade installed packagesIn other words:
同步 → 刷新数据库 → 升级-Rns is also worth committing to muscle memory:
R = Remove
n = nosave,不生成受管理配置的 .pacsave 备份
s = 顺便删无用依赖Before uninstalling, confirm that you no longer need the software and decide whether to retain .pacsave configuration backups:
sudo pacman -Rns fooOrphaned Dependencies and File Checks#
The following commands are useful for troubleshooting:
pacman -QdtFind orphaned dependencies. Remember it as:
Q = query
d = dependency
t = unrequiredInspect the query results first. Packages you still need should be marked as explicitly installed. For removal, specify only package names you have confirmed are no longer needed:
sudo pacman -Rns <CONFIRMED_ORPHAN_PACKAGE>And:
pacman -Qk fooCheck whether any files installed by a package are missing; k = check.
pacman -Qkk fooPerform a more detailed check.
Flag Compatibility in AUR Helpers#
If you use paru, most pacman query and installation flags work unchanged:
paru -S foo
paru -Ss foo
paru -Qs foo
paru -SyuThe simplest mental map is:
pacman
├── S 仓库 / 安装
│ ├── s search
│ ├── i info
│ └── yu 更新
├── Q 本机查询
│ ├── s search
│ ├── i info
│ ├── l list files
│ └── o owner
├── R 卸载
│ └── ns 干净卸载
└── U 本地 pkg.tar.zstS / Q / R / U provide a starting point for memorization. For removal and cache cleanup, still review the confirmation list and the current manual. -n does not erase all settings in a user's home directory.
References & further reading
Adapted from technical notes. Examples use generic names.
Continue along a reading path
Arch Linux
- 01Arch Linux philosophy and installation planning
- 02Kernel management, systemd-boot, and UKIs
- 03Pacman hooks, the AUR, and build security
- 04Btrfs subvolume layouts and Snapper snapshots
- 05Hardening with LUKS2, Secure Boot, and TPM2
- 06Performance choices and an everyday maintenance checklist
- 07Common Pacman commands and how to remember their flags
- 08Diagnosing slow Pacman downloads and choosing mirrors
- 09informant: Arch news and Pacman hooks
- 10Arch Linux with Btrfs: manual installation and archinstall
- 11Configuring GNOME, input methods, and snapshots
- 12GNOME laptop management and desktop customization
- 13KVM, GPU passthrough, and gaming on Arch Linux
- 14Swap, kernels, and troubleshooting on an Arch desktop