2026年2月20日 星期五

Commonly used “sudo pacman” commands on Arch Linux

  

Commonly used “sudo pacman” commands on Arch Linux



sudo pacman” is the core command for managing software (installing, updating, removing packages) with administrative privileges.



What is sudo pacman?

  • pacman = Arch Linux’s official package manager (stands for Package Archive Manager).

  • sudo = Runs pacman with root/administrator permissions (required for system-wide changes like installing/removing software).



Core Functions of sudo pacman

1. Update the system (critical first step after installation!)

Syncs your local package database with remote servers and updates all installed packages to the latest versions:

sudo pacman -Syu

  • -S: Sync (download/install packages)

  • -y: Refresh the package database (yes to sync)

  • -u: Upgrade all out-of-date packages (upgrade)



Always run this before installing new software to avoid dependency conflicts!



2. Install a package

Install one or more packages from Arch’s official repositories:

# Install a single package (e.g., VLC media player)

sudo pacman -S vlc



# Install multiple packages at once (e.g., VLC + GIMP)

sudo pacman -S vlc gimp

  • -S: Stands for Sync (the main flag for installing from repos).



3. Remove a package

Delete a package (and optionally its unused dependencies):



# Basic remove (keeps dependencies)

sudo pacman -R vlc



# Remove package + unused dependencies (recommended)

sudo pacman -Rns vlc

  • -R: Remove

  • -n: Remove configuration files (nuke configs)

  • -s: Remove unused dependencies (sweep)



4. Search for a package

Find packages in the official repos

# Search for a package by name/keyword (e.g., "firefox")

pacman -Ss firefox



# Search for already installed packages only

pacman -Qs firefox

  • -Ss: Search sync database (remote repos)

  • -Qs: Query search (local installed packages)



5. Check package details

See info about a package (version, description, dependencies):

# Info about a remote package (not installed yet)

pacman -Si vlc



# Info about an installed package

pacman -Qi vlc

  • -Si: Sync info (remote)

  • -Qi: Query info (local)



6. Clean up cached packages

Pacman stores downloaded package files (*.pkg.tar.zst) in /var/cache/pacman/pkg/—clean them to free space:



# Delete old cached packages (keep latest version)

sudo pacman -Sc



# Delete ALL cached packages (more aggressive)

sudo pacman -Scc

  • -Sc: Sync clean (safe)

  • -Scc: Sync clean completely (use if low on disk space)



7. Fix broken dependencies

If you get "dependency error" messages, repair the package database:

sudo pacman -Syyu --overwrite '*'

  • -yy: Force refresh the package database (twice = full sync)

  • --overwrite '*': Fixes issues where files are owned by multiple packages (use carefully!).



Notes for Beginners

  • Never use pacman -Sy alone (it only syncs the database, not upgrades packages)—always use -Syu to update safely.

  • Official repos vs AUR: pacman only works with Arch’s official repos (e.g., core, extra, community). For AUR packages (like Popcorn Time), use yay/pamac (which wrap pacman).

  • No sudo for read-only actions: Commands like pacman -Ss, pacman -Qi don’t need sudo (they only read data, not modify the system).



Summary

  1. sudo pacman -Syu: Update your entire system (most important command).

  2. sudo pacman -S <package>: Install a package from official repos.

  3. sudo pacman -Rns <package>: Uninstall a package + clean up dependencies/configs.

  4. pacman -Ss <keyword>: Search for packages (no sudo needed).

  5. sudo pacman -Sc: Clean cached packages to free space.



沒有留言:

張貼留言