wiki/notebook/cli.pacman.org
Gabriel Arazas 732ef34ca8 Update notebook as of 2021-10-09
Welp, I rarely take notes nowadays due to more specialized work and
stuff. Though, I should have more incentives for writing. In other
words, I'm just lazy. ;p

More free-thinking morning sessions should be done soon.
2021-10-09 18:14:46 +08:00

3.0 KiB

Command line: pacman

The built-in package manager of Arch Linux (among others). This note is based from pacman v6 and above.

Subcommands

Interestingly, pacman does not have subcommands with specific options. Instead, they go with specific flags denoting a subcommand. Practically, they're just subcommands except appearing as options.

# Rather than 'pacman install podman' or something similar.
pacman -S podman

Here's what you can do with the package manager:

  • -S are concerned with syncing the local database to the remote databases.

    • -y syncs the local database to the remote database; running with this flag alone is not recommended as the package manager will have problems.
    • -u upgrades the local database; this should be used with -y if you intend it for a proper operating system upgrade.
  • -Q is primarily from querying information from your installed packages ranging from listing installed packages to listing all of the files owned by a certain package.

    • -l, --list lists the files associated with the package.
    • -i, --info prints information about the package.
  • -F are mostly query-related operations with the database.
  • -R removes installed packages.

    • -n, --nosave removes the configuration files associated with the package; this doesn't remove files from the home directory, though.
    • -s, --recursive will recursively removes dependencies that are not used anywhere else.

You can see more of them in the "Operations" section of the manual page (i.e., pacman.1).

Examples

Welp, this is what you came for so let's go ahead.

Quickstart

It's a package manager so it's supposed to do basic package manager stuff. All of the shown commands are in longform with the shortform just commented for practical purposes.

# Search for a pacakge
# pacman -Ss podman
pacman --sync --search podman

# Install a package
# pacman -S podman
pacman --sync podman

# Uninstall a package
# pacman -Rns podman
pacman --remove --no-save --recursive podman

# Upgrade the system
# pacman -Syu
pacman --sync --refresh --upgrade

Package search selection

With everybody's favorite fuzzy finder, fzf.

pacman --sync --quiet --search pkg | fzf --prompt "Package to install > " | xargs doas pacman --sync

You can also create a search selection with all of the packages with the following one-liner.

pacman -S --list --quiet \
    | fzf --multi --prompt "Install package(s) > " \
    | xargs doas pacman -S --noconfirm

Package removal selection

Another interactive script with fzf.

pacman -Q --native --quiet | fzf --multi --prompt "Remove installed package(s) > " | xargs doas pacman -Rns --noconfirm