By Mohamad Wael

Posted :

Pacman Cheat sheet

Updating Pacman Database:

pacman --sync --refresh
# Update the packages database,
# so the packages which are available
# remotely, and which can be installed.
# You can do:
pacman --sync --refresh --refresh
# to force a database update.

Querying Available Packages:

pacman --sync --search 'regex'
# Search the names and descriptions,
# in the synced database
# of available remote packages,
# for the regular expression.
# Examples:
pacman --sync --search 'emac.*'
pacman --sync --search '^modified$'
# Additionally, you can
# search for packages
# online:
# https://archlinux.org/packages/


pacman --sync --list
# List all remote packages,
# from all repositories.
# If you provide a repository name,
# this will only list, the remote packages,
# from this repository, as in
pacman --sync --list repo_name
# Examples:
pacman --sync --list core
pacman --sync --list extra
pacman --sync --list community


pacman --sync --groups
# List all remote packages groups
# If you specify a group name,
# as in:
pacman --sync --groups base-devel
# it will list all of the packages
# belonging to this group.


pacman --sync --info a_package_name
# Get detailed information, about a
# remote package.
# If no package name is provided,
# as in:
pacman --sync --info
# Get detailed information about
# all remote packages.

Querying Installed packages

pacman --query --unrequired
# List the installed packages, which
# are not required, by other
# installed packages.
# To list the installed packages, which
# are optionally required, by other
# installed packages:
pacman --query --unrequired --unrequired


pacman --query --deps
# List only the packages, which were
# installed, as being part of a
# dependency.


pacman --query --deps --unrequired
# List the packages which were
# installed as part of being a
# dependency, and which are no
# longer required.
# You can list dependencies, which
# are optionally required, by using
pacman --query --deps --unrequired --unrequired


pacman --query --explicit
# List all the packages, which
# were explicitly installed.


pacman --query --foreign
# List only packages, which were not
# installed from a repository, as in
# for example, installed manually.
# To do the inverse, so to list
# only non foreign packages, you
# can use:
pacman --query --native


pacman --query --upgrades
# List all the installed packages,
# that require to be upgraded.


pacman --query --groups a_group_name
# List installed packages, related
# to a group. For example:
pacman --query --groups xorg-apps
# If no group is specified,
# list all groups, installed
# packages.


pacman --query --info a_package_name
# Get information about an installed
# package.
# If no package name is provided,
# displays, all installed packages
# information.


pacman --query --list a_package_name
# List files pertaining to an installed
# package.
# If no package name is provided,
# lists all the files, pertaining
# to all these installed packages.


pacman --query --search regex
# Only search, the installed packages,
# names and descriptions, for a matching
# regex. For example:
pacman --query --search 'emac.*'


pacman --query --changelog a_package_name
# View, if available, the changelog,
# of an installed package.

Installing/Upgrading:

pacman --sync a_package_or_group_name
# Install or update, the named packages,
# or groups of packages.
# If a package, or group, is already
# installed, and even if up to
# date, they are going to be
# reinstalled.
# This can be disabled by
# using :
pacman --sync --needed a_package_or_group_name
# This will only install, or update the
# named packages, or groups,
# if needed.
# If a package or group, exists in multiple
# repositories, you can select, the
# repository from which, the package,
# or group, are installed, by using:
pacman --sync repo/package_or_group
# Example:
pacman --sync extra/cosmic


pacman --sync --sysupgrade
# Upgrades all outdated packages.
# Be sure to refresh first, or
# you can do both
# using the same command:
pacman --sync --refresh --sysupgrade
# If you want to ignore
# certain packages from
# being upgraded, you
# can use --ignore, as in:
pacman --sync --sysupgrade --ignore nano
# If you want to ignore
# groups of packages from
# being upgraded, you
# can use --ignoregroup, as in:
pacman --sync --sysupgrade --ignoregroup qt5

Removing:

pacman --remove a_package_or_group_name
# Remove the named packages,
# or all packages, of the named
# package groups.


pacman --remove --recursive a_package_or_group_name
# Remove the named packages, or
# groups of packages, and all of
# their dependencies.


pacman --remove --recursive $(pacman --query --deps --unrequired --quiet)
# Remove all unrequired
# dependencies.


pacman --remove --cascade a_package_or_group_name
# Remove the named package, or group
# of packages, and all packages, which
# depend on the named package,
# recursively.
# You can use --unneeded with
# --cascade, when removing a
# group, this will remove packages,
# which are not needed by another
# package, and avoids breaking
# dependencies.

Cleanup:

pacman --sync --clean --clean
# Remove all files from the
# cache and database
# directories.
# In other words, remove
# downloaded packages,
# and unused databases.
pacman --sync --clean
# Acts the same,
# but instead of removing
# all the downloaded packages,
# it will only remove the
# downloaded packages, that
# are no longer installed
# from cache.

Help:

pacman --help
# Displays the list of operations,
# that can be performed by
# pacman.


pacman --help --operation_name
# Get detailed help,
# concerning the specified
# operation.