{"slug": "pacman-cheatsheet", "title": "Pacman Cheatsheet", "summary": "This article provides a cheatsheet for using the Pacman package manager on Arch Linux. It covers commands for installing, removing, and updating packages, including options for handling optional dependencies, package groups, and regex patterns. The guide also explains how to query package databases and warns that partial system upgrades are not supported.", "body_md": "# Installing packages\n\nNote that packages often have a series of optdepends - optional dependencies - which are packages that provide additional functionality to the application, albeit not strictly required for running it. When installing a package, pacman will list its optional dependencies among the output messages, but they will not be found in pacman.log: use the pacman -Si (see Querying package databases) command to view the optional dependencies of a package, together with short descriptions of their functionality.\n\n:warning: Partial upgrades are not supported 69\n\n# Installing specific packages\n\nTo install a single package or list of packages (including dependencies), issue the following command:\n\n    $ pacman -S package_name1 package_name2 ...\n    \nTo install a list of packages with regex:\n\n    pacman -S $(pacman -Ssq package_regex)\n    \nSometimes there are multiple versions of a package in different repositories, e.g. [core] and [testing]. To install the former version, the repository needs to be defined in front:\n\n    pacman -S core/package_name\n    \nTo install a number of packages sharing similar patterns in their names – not the entire group nor all matching packages; eg. plasma:\n\n    pacman -S plasma-{desktop,mediacenter,nm}\n    \nOf course, that is not limited and can be expanded to however many levels needed:\n\n    pacman -S plasma-{workspace{,-wallpapers},pa}\n\n# Installing package groups\n\nSome packages belong to a group of packages that can all be installed simultaneously. For example, issuing the command:\n\n    pacman -S plasma\n    \nwill prompt you to select the packages from the plasma group that you wish to install.\n\nSometimes a package group will contain a large amount of packages, and there may be only a few that you do or do not want to install. Instead of having to enter all the numbers except the ones you do not want, it is sometimes more convenient to select or exclude packages or ranges of packages with the following syntax:\n\n    Enter a selection (default=all): 1-10 15\n\nwhich will select packages 1 through 10 and 15 for installation, or:\n\n    Enter a selection (default=all): ^5-8 ^2\n    \nwhich will select all packages except 5 through 8 and 2 for installation.\n\nTo see what packages belong to the plasma group, run:\n\n    pacman -Sg plasma\n    \nNote that if a package in the list is already installed on the system, it will be reinstalled even if it is already up to date. This behavior can be overridden with the --needed option.\n\n# Removing packages\n\nTo remove a single package, leaving all of its dependencies installed:\n\n    pacman -R package_name\n    \nTo remove a package and its dependencies which are not required by any other installed package:\n\n    pacman -Rs package_name\n    \nTo remove a package, its dependencies and all the packages that depend on the target package (this operation is recursive, and must be used with care since it can remove many potentially needed packages):\n\n    pacman -Rsc package_name\n    \nTo remove a package, which is required by another package, without removing the dependent package:\n\n    pacman -Rdd package_name\n  \npacman saves important configuration files when removing certain applications and names them with the extension .pacsave. To prevent the creation of these backup files use the -n option:\n\n    pacman -Rn package_name\n    \nNote that pacman will not remove configurations that the application itself creates (for example “dotfiles” in the home folder).\n\n# Upgrading packages\n\n:warning: Partial upgrades are not supported 69\n\npacman can update all packages on the system with just one command. This could take a while depending on how up-to-date the system is. The following command synchronizes the repository databases and updates the system’s packages, excluding “local” packages that are not in the configured repositories:\n\n    pacman -Syu\n    \n\n# Querying package databases\n\npacman queries the local package database with the -Q flag, the sync database with the -S flag and the files database with the -F flag. See pacman -Q --help, pacman -S --help and pacman -F --help for the respective suboptions of each flag.\n\npacman can search for packages in the database, searching both in packages’ names and descriptions:\n\n    pacman -Ss string1 string2 ...\n\nSometimes, -s's builtin ERE (Extended Regular Expressions) can cause a lot of unwanted results, so it has to be limited to match the package name only; not the description nor any other field:\n\n    pacman -Ss ^vim-\n\nTo search for already installed packages:\n\n    pacman -Qs string1 string2 ...\n\nTo search for package file names in remote packages:\n\n    pacman -Fs string1 string2 ...\n\nTo display extensive information about a given package:\n\n    pacman -Si package_name\n\nFor locally installed packages:\n\n    pacman -Qi package_name\n\nPassing two -i flags will also display the list of backup files and their modification states:\n\n    pacman -Qii package_name\n\nTo retrieve a list of the files installed by a package:\n\n    pacman -Ql package_name\n\nTo retrieve a list of the files installed by a remote package:\n\n    pacman -Fl package_name\n\nTo verify the presence of the files installed by a package:\n\n    pacman -Qk package_name\n\nPassing the k flag twice will perform a more thorough check.\n\nTo query the database to know which package a file in the file system belongs to:\n\n    pacman -Qo /path/to/file_name\n\nTo query the database to know which remote package a file belongs to:\n\n    pacman -Fo /path/to/file_name\n\nTo list all packages no longer required as dependencies (orphans):\n\n    pacman -Qdt\n\nTo list all packages explicitly installed and not required as dependencies:\n\n    pacman -Qet\n\nTo list a dependency tree of a package:\n\n    pactree package_name\n\nTo list all the packages recursively depending on an installed package, use whoneeds from ccr/pkgtools 4:\n\n    whoneeds package_name\n\nor the reverse flag to pactree:\n\n    pactree -r package_name\n\n# Database structure\n\nThe pacman databases are normally located at /var/lib/pacman/sync. For each repository specified in /etc/pacman.conf there will be a corresponding database file located there. Database files are xzipped tarball archives containing one directory for each package, for example for the core/which package:\n\n```\ntree which-2.20-6\n\nwhich-2.20-6\n|-- depends\n`-- desc\n```\n\nThe depends file lists the packages this package depends on, while desc has a description of the package such as the file size and the MD5 hash.\n\n# Cleaning the package cache\n\npacman stores its downloaded packages in /var/cache/pacman/pkg/ and does not remove the old or uninstalled versions automatically, therefore it is necessary to deliberately clean up that folder periodically to prevent such folder to grow indefinitely in size.\n\nThe built-in option to remove all the cached packages that are not currently installed is:\n\n    pacman -Sc\n\nOnly do this when certain that previous package versions are not required, for example for a later downgrade. pacman -Sc only leaves the versions of packages which are currently installed available, older versions would have to be retrieved through other means.\n\nIt is possible to empty the cache folder fully with pacman -Scc. In addition to the above, this also prevents from reinstalling a package directly from the cache folder in case of need, thus requiring a new download. It should be avoided unless there is an immediate need for disk space.\n\nBecause of the above limitations, consider an alternative for more control over which packages, and how many, are deleted from the cache:\n\nThe paccache script, provided by the core/pacman package itself, deletes all cached versions of each package regardless of whether they’re installed or not, except for the most recent 3, by default:\n\n    paccache -r\n\nNote that you can create hooks to run this automatically after every pacman transaction.\n\nYou can also define how many recent versions you want to keep:\n\n    paccache -rk 1\n\nTo remove all cached versions of uninstalled packages, re-run paccache with:\n\n    paccache -ruk0\n\nSee paccache -h for more options.\n\n# Additional commands\n\nDownload a package without installing it:\n\n    pacman -Sw package_name\n\nInstall a local package that is not from a remote repository (e.g. the package is built from a source tarball in the CCR 7):\n\n    pacman -U /path/to/package/package_name-version.pkg.tar.xz\n\nTo keep a copy of the local package in pacman’s cache, use:\n\n    pacman -U file:///path/to/package/package_name-version.pkg.tar.xz\n\nInstall a remote package (not from a repository stated in pacman’s configuration files):\n\n    pacman -U http://www.example.com/repo/example.pkg.tar.xz\n\nTo inhibit the -S, -U and -R actions, -p can be used.\n\npacman always lists packages to be installed or removed and asks for permission before it takes action.\n\n# Installation reason\n\nThe pacman database distinguishes the installed packages in two groups according to the reason why they were installed:\n\nexplicitly-installed are the packages that were literally passed to a generic pacman -S or -U command;\ndependencies are the packages that, despite never (in general) having been passed to a pacman installation command, were implicitly installed as a dependency of another package that was explicitly installed.\nWhen installing a package, it is possible to force its installation reason to dependency with:\n\n    pacman -S --asdeps package_name\n\nWhen _re_installing a package, though, the current installation reason is preserved by default.\n\nThe list of explicitly-installed packages can be shown with pacman -Qe, while the complementary list of dependencies can be shown with pacman -Qd.\n\nTo change the installation reason of an already installed package, execute:\n\n    pacman -D --asdeps package_name\n\nUse --asexplicit to do the opposite operation.\n\nNote that installing optional dependencies with --asdeps will cause it such that if you remove orphan packages, pacman will also remove leftover optional dependencies.\n\n# Search for a package that contains a specific file\n\nSync the files database (you can set a cron job or a systemd timer to sync the files database regularly):\n\n    pacman -Fy\n\nSearch for a package containing a file, e.g.:\n\n    pacman -Fs pacman\n\n```\ncore/pacman 5.0.1-4\n    usr/bin/pacman\n    usr/share/bash-completion/completions/pacman\nextra/xscreensaver 5.36-1\n    usr/lib/xscreensaver/pacman\n```\n\nFor advanced functionality install ccr/pkgfile 10, which uses a separate database with all files and their associated packages.\n\n# Configuration\n\npacman’s settings are located in /etc/pacman.conf: this is the place where the user configures the program to work in the desired manner. In-depth information about the configuration file can be found in man 5 pacman.conf.\n\n## General options\n\nGeneral options are in the [options] section. Read man 8 pacman or look in the default pacman.conf for information on what can be done here.\n\n## Comparing versions before updating\n\nTo see old and new versions of available packages, uncomment the VerbosePkgLists line in /etc/pacman.conf. The output of pacman -Syu will be like this:\n\n```\nPackage (6)             Old Version  New Version  Net Change  Download Size\n\nextra/libmariadbclient  10.1.9-4     10.1.10-1      0.03 MiB       4.35 MiB\nextra/libpng            1.6.19-1     1.6.20-1       0.00 MiB       0.23 MiB\nextra/mariadb           10.1.9-4     10.1.10-1      0.26 MiB      13.80 MiB\n```\n\n## Skip package from being upgraded\n\n:warning: Partial upgrades are not supported 69\n\nTo have a specific package skipped when upgrading the system, specify it as such:\n\n    IgnorePkg=linux\n\nFor multiple packages use a space-separated list, or use additional IgnorePkg lines. Also, glob patterns can be used. If you want to skip packages just once, you can also use the --ignore option on the command-line - this time with a comma-separated list.\n\nIt will still be possible to upgrade the ignored packages using pacman -S; in this case pacman will remind you that the packages have been included in an IgnorePkg statement.\n\n## Skip package group from being upgraded\n\n:warning: Partial upgrades are not supported 69\n\nAs with packages, skipping a whole package group is also possible:\n\n    IgnoreGroup=plasma\n\n## Skip files from being installed to system\n\nTo always skip installation of specific directories list them under NoExtract. For example, to avoid installation of systemd units use this:\n\n    NoExtract=usr/lib/systemd/system/*\n    \nLater rules override previous ones, and you can negate a rule by prepending !. Note that pacman issues warning messages about missing locales when updating a package for which locales have been cleared by localepurge or bleachbit. Commenting the CheckSpace option in pacman.conf suppresses such warnings, but consider that the space-checking functionality will be disabled for all packages.\n\n## Maintain several configuration files\n\nIf you have several configuration files (e.g. a primary configuration, and another configuration with [testing] repository enabled) and would have to share options between configurations you may use the Include option declared in the configuration files, e.g.:\n\n    Include = /path/to/common/settings\n    \nwhere /path/to/common/settings file contains the same options for both configurations.\n\n## Hooks\n\npacman can run pre- and post-transaction hooks from the /usr/share/libalpm/hooks/ directory; more directories can be specified with the HookDir option in pacman.conf, which defaults to /etc/pacman.d/hooks. Hook file names must be suffixed with .hook.\n\nFor more information on alpm hooks, see man 5 alpm-hooks.\n\n## Repositories and mirrors\n\nBesides the special general options section, each other [section] in pacman.conf defines a package repository to be used. A repository is a logical collection of packages, which are physically stored on one or more servers: for this reason each server is called a mirror for the repository.\n\nRepositories are distinguished between official repositories 70 and unofficial user repositories. The order of repositories in the configuration file matters; repositories listed first will take precedence over those listed later in the file when packages in two repositories have identical names, regardless of version number. In order to use a repository after adding it, you will need to upgrade the whole system first.\n\nEach repository section allows defining the list of its mirrors directly or in a dedicated external file through the Include directive: for example, the mirrors for the official repositories are included from /etc/pacman.d/mirrorlist.\n\n## Package security\n\npacman supports package signatures, which add an extra layer of security to the packages. The default configuration, SigLevel = Required DatabaseOptional, enables signature verification for all the packages on a global level: this can be overridden by per-repository SigLevel lines.\n", "url": "https://wpnews.pro/news/pacman-cheatsheet", "canonical_source": "https://gist.github.com/HFTrader/4fb15d461d86634fd1cba5d251ca7925", "published_at": "2020-04-27 23:15:52+00:00", "updated_at": "2026-05-23 08:39:23.739694+00:00", "lang": "en", "topics": ["developer-tools", "open-source"], "entities": ["pacman"], "alternates": {"html": "https://wpnews.pro/news/pacman-cheatsheet", "markdown": "https://wpnews.pro/news/pacman-cheatsheet.md", "text": "https://wpnews.pro/news/pacman-cheatsheet.txt", "jsonld": "https://wpnews.pro/news/pacman-cheatsheet.jsonld"}}