Skip to content

This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!


pacman

pacman is the Arch Linux package manager. It combines a simple binary package format with an easy to use build system. The goal of pacman is to make it possible to easily manage packages, whether they are from the official repositories or the user's own builds.

Reference(s)

Table of contents


Install

pacman-contrib

[OPTIONAL]

This package contains contributed scripts and tools for pacman systems (e.g. pactree and checkupdates).

You can optionally install it to use those tools:

# pacman -S pacman-contrib

TODO: run $ pacman -Ql pacman pacman-contrib | grep -E 'bin/.+' to see the full list of pacman-contrib tools

informant

[OPTIONAL]

An Arch Linux news reader designed to also be used as a pacman hook, which prevents you from updating if there is fresh Arch news that you have not read since the last update ran.

ancient-packages

[OPTIONAL]


Config

See https://wiki.archlinux.org/index.php/Pacman#Configuration
See https://jlk.fjfi.cvut.cz/arch/manpages/man/pacman.conf.5

  • Edit the pacman config file as you wish:

    # vi /etc/pacman.conf
        > ...
    

  • Skip a specific package from being upgrading during a system update:

    # vi /etc/pacman.conf
        > ...
     +  > IgnorePkg=package_name
        > ...
    

  • Skip a package group from being upgrading during a system update:

    # vi /etc/pacman.conf
        > ...
      + > IgnoreGroup=group_name
        > ...
    

Hooks

WIP

See https://wiki.archlinux.org/index.php/Pacman#Hooks
See https://www.archlinux.org/pacman/alpm-hooks.5.html

pacman 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.

E.g. pacman post transaction hook to be notified if a transaction orphaned a package. This can be useful for being notified when a package has been dropped from a repository, since any dropped package will also be orphaned on a local installation, unless it was explicitly installed (see https://wiki.archlinux.org/index.php/Pacman#Querying_package_databases):

# vi /etc/pacman.d/hooks/orphans.hook
    > [Trigger]
    > Operation = Remove
    > Operation = Install
    > Operation = Upgrade
    > Type = Package
    > Target = *
    >
    > [Action]
    > Description = Be notified if a transaction orphaned a package.
    > When = PostTransaction
    > Exec = /usr/bin/bash -c "/usr/bin/pacman -Qtd || /usr/bin/echo '=> None found.'"

Other example: https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks#List_of_installed_packages


Use

Installing packages

  • Install one or multiple specific packages:

    # pacman -S package_name1 package_name2
    

  • Install a package as a dependency (in opposition to explicitly installed):

    # pacman -S --asdeps package_name
    

  • Change the "reason" of an installed package, from explicitly to dependency:

    # pacman -D --asdeps package_name
    

  • Change the "reason" of an installed package, from dependency to explicitly:

    # pacman -D --asexplicit package_name
    

  • Install a package group:

    # pacman -S package_group # e.g. "gnome"
    

  • Print what packages belong to a package group:

    # pacman -Sg package_group # e.g. "gnome"
    

Maintain a list of installed packages

Updating packages

  • Update a package:
    # pacman -Syu package_name
    
    (NOTE: in practice, do not run # pacman -Sy package_name but # pacman -Syu package_name in order to avoid dependency issues)

Updating system

  • Print for how long the system hasn't been updated:

    $ sync_date=$(egrep 'pacman -Syu' /var/log/pacman.log | tail -1 | grep -Eo '[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}T[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}') # https://stackoverflow.com/questions/26881104/extract-date-from-a-file-name-in-unix-using-shell-scripting
    $ secs=$(( $(date -d now +%s) - $(date -d $sync_date +%s) ))
    $ days=$(echo "$secs / (60 * 60 *24)" | bc)
    $ echo $days
    

  • Read the news:

  • [OPTIONAL] Check updates (see above pacman-contrib installation section and below checkupdates usage section).

  • Update the system:

    # pacman -Syu
    

  • See the bellow troubleshooting section if any problem is encountered.

  • Immediately act on alerts if any.

  • Promptly deal with new configuration files if any.

  • # reboot

  • Remove orphans (packages that were installed as a dependency, but no other packages depend on them after the system update):

    # pacman -Qtd # this command will print orphans
    # pacman -Rns $(pacman -Qtdq) # this command will remove orphans (see <https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks#Removing_unused_packages_(orphans)>)
    

  • Remove dropped packages (packages that no longer are in the remote repositories, but still are on your local system):

    # pacman -Qm # this command will print dropped packages (then remove them manually if any)
    

    Warning

    # pacman -Qm will also print manually installed packages (e.g. with AUR). To exclude packages that are (still) available on the AUR, use the ancient-packages tool (see above ancient-packages installation section and below #ancient-packages usage section)..

  • [OPTIONAL] Clean package cache (see above pacman-contrib installation section and below paccache usage section).

Removing packages

  • Remove a package and its dependencies which are not required by any other installed package:

    # pacman -Rs package_name
    

  • Remove a single package, leaving all of its dependencies installed:

    # pacman -R package_name
    

  • Remove a package and its dependencies (which are not required by any other installed package) and prevent the creation of it's configuration files backup (*.pacsave files):

    # pacman -Rsn package_name
    

    Info

    pacman default behavior is to backup configuration files instead of deleting them. But even when told to delete them (preventing the creation of backups) pacman can't remove configuration files that the application created itself (e.g. "dotfiles" in the home folder).

Searching packages

  • Search for packages in the database, for both packages' names and descriptions containing string1 and string2:

    $ pacman -Ss string1 string2 ...
    

  • Search for already installed packages' names and descriptions containing string1 and string2:

    $ pacman -Qs string1 string2 ...
    

  • Search for package file names in "remote packages" (packages not from a repository stated in pacman's configuration files):

    # pacman -Fy # [OPTIONAL] sync the files database
    $ pacman -F string1 string2 ...
    

  • Print extensive information about a given package:

    $ pacman -Si package_name
    

  • Print extensive information about a locally installed packages:

    $ pacman -Qi package_name
    

    Tip

    Passing two -i flags will also display the list of backup files and their modification states:

    $ pacman -Qii package_name
    

  • Print locally installed packages containing matching a string:

    $ pacman -Q | grep string-to-match
    

  • Print the list of files installed by a package:

    $ pacman -Ql package_name
    

  • Print binary (or binaries) associated to a package, in order to find out what command(s) to use with a package:

    $ pacman -Ql package_name | grep /bin/
    

  • Print the list of files installed by a "remote package" (package not from a repository stated in pacman's configuration files):

    $ pacman -Fl package_name
    

  • Check the presence of the files installed by a package:

    $ pacman -Qk package_name
    

    Tip

    Passing two -k flag will perform a more thorough check:

    $ pacman -Qkk package_name
    

  • Search which package a file in the file system belongs to:

    $ pacman -Qo /path/to/file_name
    

  • Search which "remote package" (package not from a repository stated in pacman's configuration files) a file belongs to:

    $ pacman -F /path/to/file_name
    

  • List all packages no longer required as dependencies (orphans):

    $ pacman -Qdt
    

  • List all packages explicitly installed:

    $ pacman -Q
    

  • List all packages explicitly installed:

    $ pacman -Qe
    

  • List all packages explicitly installed and not required as dependencies:

    $ pacman -Qet
    

Removing packages cache

  • Remove all the cached packages that are not currently installed and the unused sync database:

    # pacman -Sc
    

    Tip

    Passing two -c flag will remove all files from the cache, this is the most aggressive approach and will leave nothing in the cache folder:

    # pacman -Scc
    

paccache

From the pacman-contrib package (see https://wiki.archlinux.org/index.php/Pacman#Cleaning_the_package_cache and https://jlk.fjfi.cvut.cz/arch/manpages/man/paccache.8)

  • Delete all cached versions of installed and uninstalled packages, except for the most recent 3 (by default):

    # paccache -r
    

  • Define how many recent versions you want to keep when deleting cached versions. E.g. to retain only one past version use:

    # paccache -rk1
    

  • Remove all cached versions of uninstalled (-u) packages:

    # paccache -ruk0
    # paccache -r
    

makepkg?

pactree

From the pacman-contrib package (see https://wiki.archlinux.org/index.php/Pacman#Pactree)

  • Print the dependency tree of a package:

    $ pactree package_name
    

  • Print the dependent tree of a package:

    $ pactree -r package_name
    

checkupdates

From the pacman-contrib package:

Informant

ancient-packages

Hooks

Tip

/usr/share/libalpm/hooks is for system managed hooks, and /etc/pacman.d/hooks for user overrides.

Mirrors

Reference(s)

Troubleshooting

  • https://wiki.archlinux.org/index.php/Pacman#Troubleshooting

  • If getting the following error when installing a package (see https://forum.artixlinux.org/index.php/topic,952.0.html):

    ...
    ... requested URL returned error: 404
    ... requested URL returned error: 404
    ... requested URL returned error: 404
    warning: failed to retrieve some files
    error: failed to commit transaction (failed to retrieve some files)
    Errors occurred, no packages were upgraded.
    

    Then you might have to update your mirrors located in /etc/pacman.d/mirrorlist (e.g. for Artix see https://gitea.artixlinux.org/packages/artix-mirrorlist/src/branch/master/mirrorlist).

    Then update the system with # pacman -Syyu (passing two -y, or --refresh, flags will force a refresh of all package lists even if they appear to be up to date).

  • If you get this kind of error (see https://bbs.archlinux.org/viewtopic.php?id=272835):

    error: package-name: signature from "..." is unknown trust
    
    Then this probably means your system hasn't been updated for a little while, in this case you might just have to update archlinux-keyring:
    $ sudo pacman -S archlinux-keyring
    
    After that, you can try to sudo pacman -Syu again.

    Note for Artix users, you might have to update artix-keyring:

    $ sudo pacman -S artix-keyring
    

  • If you get this kind of error:

    error: package-name: signature from "..." is marginal trust
    :: File /path/to/package-name.pkg.tar.zst is corrupted (invalid or corrupted package (PGP signature)).
    
    Then this probably means your system hasn't been updated for a little while, in this case you might just have to update archlinux-keyring:
    $ sudo pacman -S archlinux-keyring
    
    After that, you can try to sudo pacman -Syu again.

    Note for Artix users, you might have to update artix-keyring:

    $ sudo pacman -S artix-keyring
    


If this cheat sheet has been useful to you, then please consider leaving a star here.