Linux pacman command
pacman (Package Manager) is the default package management tool for Arch Linux and its derivatives (such as Manjaro). It is a powerful command-line tool for installing, updating, removing, and managing software packages.
The main features of pacman:
- A simple and easy-to-use command-line interface
- Automatic dependency handling
- Support for local and remote packages
- Complete system update capabilities
- Efficient package query and search capabilities
Basic Syntax
The basic syntax of the pacman command is as follows:
sudo pacman [选项] [操作] [包名/其他参数]
Where:
sudo: Most pacman operations require root privileges选项: Flags that modify the command's behavior操作: Specify the main function to perform包名: The names of the packages to operate on
Common operation commands
System updates
Example
Update all installed packages
sudo
pacman
-Syu
Update only the package database (without actually updating software)
sudo
pacman
-Sy
Package installation
Example
Install a single package
sudo
pacman
-S
Package name
Install multiple packages
sudo
pacman
-S
Package name
1
Package name
2
Package name
3
Install a local package file (without handling dependencies)
sudo
pacman
-U
/
Path
/
to
/
pkgname.pkg.tar.zst
Package removal
Example
Remove a package but keep its dependencies
sudo
pacman
-R
Package name
Remove a package and its dependencies that are no longer needed
sudo
pacman
-Rs
Package name
Remove a package and all of its configuration files
sudo
pacman
-Rns
Package name
Package queries
Example
Search for packages (by name and description)
pacman
-Ss
Keyword
List installed packages
pacman
-Q
Find which package a file belongs to
pacman
-Qo
/
Path
/
to
/
file
Display detailed package information
pacman
-Qi
Package name
Clear cache
Example
Clean the cache of uninstalled packages
sudo
pacman
-Sc
Clean the cache of all packages (including installed ones)
sudo
pacman
-Scc
Commonly used options
| Option | Description |
|---|---|
-S |
Sync/install packages |
-R |
Remove a package |
-Q |
Query the local package database |
-U |
Install a local package file |
-y |
Update the package database |
-u |
Upgrade packages |
-s |
Include descriptions when searching |
-i |
Display package information |
-c |
Clear cache |
-d |
Skip dependency checks |
-f |
Force operations |
--noconfirm |
Skip all confirmation prompts |
Practical Application Examples
Example 1: Install and configure a development environment
Example
Update the system
sudo
pacman
-Syu
Install the development toolchain
sudo
pacman
-S
base-devel
git
python
Verify the installation
pacman
-Q
|
grep
python
Example 2: Find and install a media player
Example
Search for media players
pacman
-Ss
media player
Install the VLC media player
sudo
pacman
-S
vlc
View VLC's dependencies
pacman
-Qi
vlc
Example 3: Completely remove software you no longer need
Example
Find the package to remove
pacman
-Qs
game
Remove the game and its dependencies and configuration
sudo
pacman
-Rns
steam
Common Problem Solutions
1. Dependency Conflicts
When you encounter dependency conflicts, you can try:
Example
Force-downgrade a specific package
sudo
pacman
-U
https:
//
archive.archlinux.org
/
packages
/
p
/
Package name
/
pkgname-version.pkg.tar.zst
Or try to repair dependencies
sudo
pacman
-Syu
--overwrite
'*'
2. Database lock
If you encounter a "could not lock database" error:
Example
Delete the lock file
sudo
rm
/
var
/
lib
/
pacman
/
db.lck
3. Insufficient space
Clean old version caches:
Example
View the space used by the cache
du
-sh
/
var
/
cache
/
pacman
/
pkg
/
Clean old versions
sudo
pacman
-Sc
Best Practice Recommendations
- Update the system regularly: Run at least once a week
sudo pacman -Syu - Read the output: pacman's output contains important information; do not confirm blindly
- Back up important data: Back up important files before major system updates
- Use an AUR helper: For software in the Arch User Repository (AUR), consider using yay or paru
- Consult the Arch Wiki: When you run into problems, the Arch Wiki usually has detailed solutions
Advanced Tips
View package file contents
Example
List the files contained in a package
pacman
-Ql
Package name
Extract a specific package file
sudo
pacman
-Sw
Package name
&
amp;
&
amp;
tar
-xf
/
var
/
cache
/
pacman
/
pkg
/
Package name
.pkg.tar.zst
Build a custom package
Example
Download the PKGBUILD file
asp
export
Package name
Enter the directory and build
cd
Package name
makepkg
-si
Query file ownership
Example
Find which package provides a specific command
pacman
-Qo
$
(
which
command_name
)
For example, find which package the vim command belongs to
pacman
-Qo
$
(
which
vim
)
By mastering the pacman command, you can efficiently manage all packages on an Arch Linux system. Remember that pacman is a powerful tool and a wrong command can cause system problems, so always understand what a command does before running it.
Linux Command Reference