pacman – ArchWiki – ABOUT MAG 2020

O Pac Man package manager is one of the main distinguishing features of Arch Linux. It combines a simple binary package format with an easy to use building system. The objective of Pac Man is to enable easy management of packages, be they from official repositories or the user’s own builds.

Pac Man keeps the system up to date by synchronizing the package lists with the master server. This server / client model also allows the user to download / install packages with a simple command, complete with all necessary dependencies.

Pac Man is written in Ç programming language and uses the bsdtar (1) tar packaging format.

Use

What follows is just a small sample of the transactions that Pac Man can perform. For more examples, see pacman (8).

Tip: For those who have used other Linux distributions, there is a useful Pacman Rosetta article.

Installing packages

note:

  • Packages usually have optional dependencies which are packages that provide additional functionality to the application, but are not strictly necessary to run it. When installing a package, Pac Man list a package’s optional dependencies, but they will not be found in pacman.log. Use the # Query of package databases command to view optional package dependencies.
  • When installing a package that you require only as an (optional) dependency on some other package (that is, it is not explicitly needed by you otherwise), it is recommended to use --asdeps option. For details, refer to the # Reason for installation section.

Installing specific packages

To install a single package or package list, including dependencies, issue the following command:

# pacman -S package_name1 package_name2 ...

To install a list of packages with regex (see this forum topic):

# pacman -S $(pacman -Ssq package_regex)

Sometimes, there are multiple versions of a package in different repositories (for example, extra and test) To install the version of extra repository in this example, the repository needs to be defined in front of the package name:

# pacman -S extra/package_name

To install multiple packages that share similar patterns in their names, you can use key expansion. For example:

# pacman -S plasma-{desktop,mediacenter,nm}

This can be expanded to as many levels as needed:

# pacman -S plasma-{workspace{,-wallpapers},pa}

Installing package groups

Some packages belong to a package group all of these can be installed simultaneously. For example, issuing the command:

# pacman -S gnome

will ask you to select packages on gnome group you want to install.

Sometimes a package group contains a large number of packages and there may be only a few that you want or don’t want to install. Instead of having to enter all the numbers, except the ones you don’t want, it is sometimes more convenient to select or delete packages or package ranges with the following syntax:

Enter a selection (default=all): 1-10 15

which will select packages 1 through 10 and 15 for installation, or:

Enter a selection (default=all): ^5-8 ^2

which will select all packages except 5 to 8 and 2 for installation.

To see which packages belong to the gnome group, run:

# pacman -Sg gnome

Also visit https://www.archlinux.org/groups/ to see which package groups are available.

note: If a package from the list is already installed on the system, it will be reinstalled even if it is already updated. This behavior can be replaced by --needed option.

Removing packages

To remove a single package, leaving all its dependencies installed:

# pacman -R package_name

To remove a package and its dependencies that are not required by any other installed package:

# pacman -Rs package_name

Sometimes, the above may refuse to perform when removing a group that contains necessary packages. In that case, try:

# pacman -Rsu package_name

To remove a package, its dependencies and all packages that depend on the destination package:

Attention: This operation is recursive and should be used with care, as it can remove many potentially needed packages.

# pacman -Rsc package_name

To remove a package, required by another package, without removing the dependent package:

# pacman -Rdd package_name

Pac Man 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:

# pacman -Rn package_name

note: Pac Man it will not remove the settings created by the application itself (for example, “dotfiles” in the home folder).

Updating packages

Pac Man you can update all packages on the system with just one command. This may take a while, depending on the system update. The following command synchronizes the repository databases and updates system packages, excluding “local” packages that are not in the configured repositories:

# pacman -Syu

Querying package databases

Pac Man queries the local package database with the -Q flag, the synchronization database with the -S flag and the file database with the -F flag. Watch pacman -Q --help, pacman -S --help and pacman -F --help for the respective sub-options of each flag.

Pac Man you can search the database for packages by searching the package names and descriptions:

$ pacman -Ss string1 string2 ...

Sometimes, -sThe built-in extended regular expressions (ERE) can cause many unwanted results, so it must be limited to match only the package name; neither description nor any other field:

$ pacman -Ss '^vim-'

To search for packages already installed:

$ pacman -Qs string1 string2 ...

To search for package file names in remote packages:

$ pacman -F string1 string2 ...

To display comprehensive information about a particular package:

$ pacman -Si package_name

For locally installed packages:

$ pacman -Qi package_name

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

$ pacman -Qii package_name

To retrieve a list of files installed by a package:

$ pacman -Ql package_name

To retrieve a list of files installed by a remote package:

$ pacman -Fl package_name

To check for the presence of files installed by a package:

$ pacman -Qk package_name

Passing the k The flag twice will perform a more thorough check.

To query the database to find out which package a file in the file system belongs to:

$ pacman -Qo /path/to/file_name

To query the database to find out which remote package a file belongs to:

$ pacman -F /path/to/file_name

To list all packages that are no longer needed as dependencies (orphans):

$ pacman -Qdt
Tip: Add the above command to a post-transaction pacman hook to be notified if a transaction orphans a package. This can be useful to be notified when a package is dropped from a repository, as any dropped package will also be orphaned in a local installation (unless it has been explicitly installed). To avoid “failed to execute command” errors when no orphan is found, use the following command to Exec on your hook: /usr/bin/bash -c "/usr/bin/pacman -Qtd || /usr/bin/echo '=> None found.'"

To list all packages installed explicitly and not needed as dependencies:

$ pacman -Qet

Watch Pacman / Tips and tricks for more examples.

Pactree

To view a package’s dependency tree:

$ pactree package_name

To view the dependent tree of a package, pass the reverse flag -r for pactreeor use who needs in pkgtoolsAUR.

Database structure

O Pac Man databases are usually located in /var/lib/pacman/sync. For each repository specified in /etc/pacman.conf there will be a corresponding database file located there. Database files are gzip-compressed tar files containing a directory for each package, for example, for the which one package:

$ tree which-2.21-5
which-2.21-5
|-- desc

O desc The file contains metadata, such as package description, dependencies, file size and MD5 hash.

Clearing the package cache

Pac Man stores your downloaded packages in /var/cache/pacman/pkg/ and does not automatically remove old or uninstalled versions. This has some advantages:

  1. Allows demote a package without having to recover the previous version by other means, such as Arch Linux Archive.
  2. A package that has been uninstalled can be easily reinstalled directly from the cache folder, without requiring a new download from the repository.

However, it is necessary to deliberately clear the cache periodically to prevent the folder from growing in size indefinitely.

O paccache (8) script, provided within the pacman-contrib package, deletes all cached versions of installed and uninstalled packages, except the most recent 3, by default:

# paccache -r

Enable and begin paccache.timer discard unused packages weekly.

You can also define how many recent versions you want to keep. To keep only an earlier version, use:

# paccache -rk1

add -u/--uninstalled switch to limit the action of paccache to uninstall packages. For example, to remove all cached versions of uninstalled packages, use the following:

# paccache -ruk0

Watch paccache -h for more options.

Pac Man also has some built-in options for clearing the cache and remaining database files from the repositories that are no longer listed in the configuration file /etc/pacman.conf. Yet Pac Man does not offer the possibility to maintain several previous versions and is therefore more aggressive than paccache default options.

To remove all cached packages that are not currently installed and the unused sync database, run:

# pacman -Sc

To remove all files from the cache, use the clean option twice, this is the most aggressive approach and will not leave anything in the cache folder:

# pacman -Scc

Attention: You should avoid deleting all previous versions of installed packages and all uninstalled packages from the cache, unless you need to desperately free up some disk space. This will prevent you from downgrading or reinstalling packages without downloading them again.

pkgcachecleanAUR and pacleanerAUR There are two additional alternatives for clearing the cache.

Additional commands

Download a package without installing it:

# pacman -Sw package_name

Install a ‘local’ package that is not from a remote repository (for example, the package is from the directory AUR):

# pacman -U /path/to/package/package_name-version.pkg.tar.xz

To keep a copy of the local package in Pac Man ‘cache, use:

# pacman -U file:///path/to/package/package_name-version.pkg.tar.xz

Install a ‘remote’ package (not from a repository indicated in Pac Man ‘configuration files):

# pacman -U http://www.example.com/repo/example.pkg.tar.xz

To inhibit -S, -U and -R actions, -p can be used.

Pac Man always lists the packages to be installed or removed and asks for permission before taking action.

Reason for installation

O Pac Man The database distinguishes installed packages into two groups according to the reason they were installed:

  • explicitly installed: packages that were literally passed to a generic Pac Man -S or -U command;
  • dependencies: packages that, although never (in general) were passed to a Pac Man installation command, were installed implicitly because Requested by another package that was explicitly installed.

When installing a package, you can force your installation reason to dependency with:

# pacman -S --asdeps package_name
Tip: Installing optional dependencies with --asdeps will make sure that if you remove orphans, Pac Man it will also remove the remaining optional dependencies.

When reinstall a package, however, the current reason for installation is preserved by default.

The list of explicitly installed packages can be shown with pacman -Qe, while the complementary list of dependencies can be shown with pacman -Qd.

To change the reason for installing an already installed package, run:

# pacman -D --asdeps package_name

Use --asexplicit to do the opposite operation.

note: Using --asdeps and --asexplicit options when upgrading, as with pacman -Syu package_name --asdeps, is discouraged. This would change the reason for installing not only the package being installed, but also the packages being updated.

Search for a package that contains a specific file

Synchronize the file database:

# pacman -Fy

Search for a package containing a file, for example:

$ pacman -F pacman
core/pacman 5.2.1-1 (base base-devel) [installed]
    usr/bin/pacman
    usr/share/bash-completion/completions/pacman
extra/xscreensaver 5.43-1
    usr/lib/xscreensaver/pacman

Tip: You can set a cron job or a system timer to synchronize the file database regularly.

For advanced functionality, install pkgfile, which uses a separate database with all files and their associated packages.

Configuration

Pac Man ‘S settings are located at /etc/pacman.conf: is the place where the user configures the program to work in the desired way. Detailed information about the configuration file can be found at pacman.conf (5).

General options

The general options are in the [options] section. Read pacman.conf (5) or look in the pattern pacman.conf for information on what can be done here.

Comparing versions before upgrading

To see old and new versions of available packages, uncomment the “VerbosePkgLists” line in /etc/pacman.conf. The output of pacman -Syu it will be like this:

Package (6)             Old Version  New Version  Net Change  Download Size

extra/libmariadbclient  10.1.9-4     10.1.10-1      0.03 MiB       4.35 MiB
extra/libpng            1.6.19-1     1.6.20-1       0.00 MiB       0.23 MiB
extra/mariadb           10.1.9-4     10.1.10-1      0.26 MiB      13.80 MiB

Bypass package update

Attention: Be careful when skipping packages, as partial updates are not supported.

For a specific package to be ignored when update the system, specify it as such:

IgnorePkg=linux

For multiple packages, use a space-separated list or use IgnorePkg lines. Besides that, glob patterns can be used. If you want to skip packages only once, you can also use the --ignore command line option – this time with a comma-separated list.

It will still be possible to update the ignored packages using pacman -S: in this case Pac Man remember that the packages were included in a IgnorePkg declaration.

Bypass package group update

Attention: Be careful when ignoring package groups, as partial updates are not supported.

As with packages, it is also possible to skip an entire group of packages:

IgnoreGroup=gnome

Skip file update

All files listed with a NoUpgrade The policy will never be touched when installing / updating a package, and new files will be installed with a .pacnew extension.

NoUpgrade=path/to/file

note: The path refers to the files in the package archive. Therefore, do not include the start bar.

Skip installing files on the system

To always skip installing specific directories, list them in NoExtract. For example, to avoid installing systemd units use this:

NoExtract=usr/lib/systemd/system/*

Subsequent rules replace previous ones and you can deny a rule by placing it !.

Tip: Pac Man issues warning messages about missing language codes when updating a package for which language codes have been cleared by localepurge or bleachbit. Commenting on the CheckSpace option in pacman.conf suppresses these warnings, but consider that space checking functionality will be disabled for all packages.

Keep multiple configuration files

If you have multiple configuration files (for example, main configuration and configuration with test repository enabled) and would have to share options between settings that you can use Include option declared in the configuration files, for example:

Include = /path/to/common/settings

Where /path/to/common/settings The file contains the same options for both configurations.

Hooks

Pac Man can perform pre- and post-transaction hooks from the /usr/share/libalpm/hooks/ directory; more directories can be specified with the HookDir option in pacman.conf, whose default is /etc/pacman.d/hooks. Hook file names must have the suffix .hook. Pacman hooks are not interactive.

Pac Man hooks are used, for example, in combination with systemd-sysusers and systemd-tmpfiles automatically create users and system files during package installation. For example, package tomcat8 specifies that you want a system user called tomcat8 and certain directories owned by that user. O Pac Man hooks systemd-sysusers.hook and systemd-tmpfiles.hook summon up systemd-sysusers and systemd-tmpfiles When Pac Man determines that package tomcat8 contains files that specify users and tmp files.

For more information on alpm hooks, see alpm hooks (5).

Repositories and mirrors

In addition to the special [options] section, each other [section] in pacman.conf defines a package repository to be used. AN repository it is a logical collection of packages, which are physically stored on one or more servers: for this reason, each server is called a mirror to the repository.

Repositories are distinguished between official and not official. The order of the repositories in the configuration file is important; the repositories listed first will take precedence over those listed later in the file when packages in two repositories have identical names, regardless of the version number. To use a repository after adding it, you will need to improvement the whole system first.

Each section of the repository allows you to define the list of your mirrors directly or in a dedicated external file via Include directive: for example, mirrors for official repositories are included in /etc/pacman.d/mirrorlist. see the Mirrors mirror configuration item.

Package security

Pac Man supports package signatures, which add an extra layer of security to packages. The default setting, SigLevel = Required DatabaseOptional, enables signature verification for all packages at a global level: this can be replaced by repository SigLevel lines. For more details on signing packages and verifying signatures, see pacman key.

Problems solution

“Failed to confirm transaction (conflicting files)” error

If you see the following error: [1]

error: could not prepare transaction
error: failed to commit transaction (conflicting files)
package: /path/to/file exists in filesystem
Errors occurred, no packages were upgraded.

This is happening because Pac Man has detected a file conflict and, by default, will not replace files for you. This is by design, not a failure.

The problem is usually trivial to resolve. A safe way is to first check if another package has the file (pacman -Qo /path/to/file) If the file belongs to another package, register a bug report. If the file does not belong to another package, rename the file that ‘exists on the file system’ and issue the update command again. If all goes well, the file can be removed.

If you installed a program manually without using the Pac Man, for example, through make install, you need to remove / uninstall this program with all its files. See too Pacman Tips # Identify files that do not belong to any package.

Every installed package provides a /var/lib/pacman/local/package-version/files file that contains metadata about this package. If that file gets corrupted, is empty or disappears, it will result in file exists in filesystem errors when trying to update the package. This error usually concerns only one package. Instead of manually renaming and later removing all files that belong to the package in question, you can explicitly run pacman -S --overwrite glob package to force Pac Man overwrite files that match glob.

“Failed to confirm transaction (invalid or corrupted package)” error

Look to .part files (partially downloaded packages) in /var/cache/pacman/pkg/ and remove them (usually caused by using a XferCommand in pacman.conf)

# find /var/cache/pacman/pkg/ -iname "*.part" -delete

Error “Failed to start the transaction (cannot lock database)”

When Pac Man is about to change the package database, for example, installing a package, it creates a lock file in /var/lib/pacman/db.lck. This avoids another instance of Pac Man trying to change the package database at the same time.

What if Pac Man is interrupted when changing the database, this stale lock file may remain. If you are sure that no instance of Pac Man is running, delete the lock file:

# rm /var/lib/pacman/db.lck

Packages cannot be recovered at installation

This error manifests itself as Not found in sync db, Target not found or Failed retrieving file.

First, check if the package really exists. If you are sure that the package exists, your package list may be out of date. Try to run pacman -Syu to force an update of all package and update lists. Also check that the selected options mirrors are up to date and repositories are configured correctly.

It may also be that the repository containing the package is not activated on your system, for example the package may be on multilib repository but multilib is not enabled on your pacman.conf.

See too FAQ # Why is there only one version of each library shared in the official repositories?.

Pacman fails during an update

In which case Pac Man fails with a “write database” error when removing packages and reinstalling or updating packages fails next, do the following:

  1. Boot using the Arch installation media. Preferably, use recent media so that the Pac Man version matches / is newer than the system.
  2. Mount the system’s root file system, for example mount /dev/sdaX /mnt as root and check that the assembly has enough space with df -h
  3. Mount the proc, sys and dev file systems as well: mount -t proc proc /mnt/proc; mount --rbind /sys /mnt/sys; mount --rbind /dev /mnt/dev
  4. If the system uses standard databases and directories, you can now update the system settings. Pac Man database and update it via pacman --sysroot /mnt -Syu as root.
  5. After upgrading, one way to check for packages that are not updated, but still have problems: find /mnt/usr/lib -size 0
  6. Followed by a reinstallation of any package still damaged via pacman --sysroot /mnt -S package.

Manually reinstalling pacman

Attention: It is extremely easy to break your system even worse using this approach. Use this only as a last resort if the #Pacman crashes during an update it is not an option.

Even if Pac Man is terribly broken, you can fix it manually by downloading the latest packages and extracting them to the correct locations. The approximate steps to be taken are:

  1. Determine the Pac Man dependencies to install
  2. Download each pack from one mirror of your choice
  3. Extract each package to root
  4. Reinstall these packages with pacman -S --overwrite to update the package database properly
  5. Perform a complete system update

If you have a working Arch system, you can see the complete list of dependencies with:

$ pacman -Q $(pactree -u pacman)

But you may need to update only a few of them, depending on your problem. An example of extracting a package is

# tar -xvpwf package.tar.xz -C / --exclude .PKGINFO --exclude .INSTALL --exclude .MTREE --exclude .BUILDINFO

Note the use of w flag for interactive mode. Running non-interactively is very risky as you can replace an important file. Also be careful to extract packages in the correct order (that is, dependencies first). This forum post contains an example of this process where only a few Pac Man dependencies are broken.

“Could not find root device” error after restart

Most likely the initramfs was corrupted during a core update (misuse of Pac Man ‘s --overwrite option may be a cause). There are two options; first try the Fall back input.

Tip: If you removed the Fall back you can always press the Tab when the boot loader menu appears (for Syslinux) or e (for GRUB or systemd-boot), rename it initramfs-linux-fallback.img and press Enter or b (Depending on your boot loader) to initialize with the new parameters.

After the system starts, execute this command (for stock linux kernel) from the console or a terminal to rebuild the initramfs image:

# mkinitcpio -p linux

If that doesn’t work, from a current version of Arch (CD / DVD or USB stick), Mount your root and boot partitions. So chroot using arc-chroot:

# arch-chroot /mnt
# pacman -Syu mkinitcpio systemd linux
note:

  • If you don’t have a current version or if you only have some other “live” Linux distribution, you can chroot using the old way. Obviously, there will be more typing than simply running the arch-chroot script.
  • What if Pac Man fail with Could not resolve host, please Check your internet connection.
  • If you are unable to enter the arch-chroot or chroot environment, but need to reinstall the packages, you can use the command pacman --sysroot /mnt -Syu foo bar use Pac Man on your root partition.

Reinstalling the kernel (the linux package) will automatically generate the initramfs image with mkinitcpio -p linux. There is no need to do this separately.

Then, it is recommended that you run exit, umount /mnt/{boot,} and reboot.

“_is_unknown_trust, _installation_failed”> “User signature “is an unknown trust, the installation failed

Potential solutions:

Order on import of PGP keys

If you are installing Arch with an outdated ISO, you will probably be asked to import PGP keys. Agree to download the key to continue. If you are unable to add the PGP key successfully, update the keyring or update archlinux-keyring (see “_is_unknown_trust, _installation_failed”> above)

Error: “0123456789ABCDEF” key could not be searched remotely

If packages are signed with new keys, which have only recently been added to archlinux-keyring, these keys are not available locally during the upgrade (chicken egg issue). The installed archlinux-keyring it does not contain the key until it is updated. Pacman tries to get around this by searching through a key server, which may not be possible, for example behind proxies or firewalls and results in the declared error. Improvement archlinux-keyring first as shown “_is_unknown_trust, _installation_failed”> above.

“_is_invalid, _installation_failed”> Signature of “User “is invalid, installation failed

When the system time is defective, signature keys are considered expired (or invalid) and package signature checks will fail with the following error:

error: package: signature from "User " is invalid
error: failed to commit transaction (invalid or corrupted package (PGP signature))
Errors occured, no packages were upgraded.

Be sure to correct the system time, for example, with ntpd -qg run as root and run hwclock -w as root before subsequent installations or upgrades.

“Warning: current location is invalid; using standard error” C “locale”

As the error message says, your locale is not configured correctly. Watch Locality.

Pacman does not respect proxy settings

Check that the relevant environment variables ($http_proxy, $ftp_proxy etc.) are configured. If you use Pac Man with sudo, you need to configure sudo to pass these environment variables to pacman. In addition, ensure the configuration of dirmngr has honor-http-proxy in /etc/pacman.d/gnupg/dirmngr.conf to honor the proxy when updating the keys.

How to reinstall all packages, keeping information about whether something was explicitly installed or as a dependency?

To reinstall all native packages: pacman -Qnq | pacman -S - or pacman -S $(pacman -Qnq) (The -S option preserves the reason for installation by default).

You will need to reinstall all external packages, which can be listed with pacman -Qmq.

“Unable to open shared object file” error

It looks like it was earlier Pac Man transaction removed or corrupted shared libraries needed to Pac Man in itself.

To recover from this situation, you need to unzip the necessary libraries on your file system manually. First find the package that contains the missing library, then locate it in the directory Pac Man cache (/var/cache/pacman/pkg/) Unzip the shared library required for the file system. This will allow you to run Pac Man.

Now you need reinstall the broken package. Note that you need to use --overwrite signal how you just unzipped system files and Pac Man don’t know about it. Pac Man will correctly replace our shared library file with one from the package.

That’s it. Update the rest of the system.

Freezing package downloads

Some problems have been reported about network problems that prevent Pac Man to update / synchronize repositories. [2] [3] When installing Arch Linux natively, these problems were resolved by replacing the default Pac Man file downloader with an alternative (see Improve pacman performance for more details). When installing Arch Linux as a guest OS on VirtualBox, this problem was also solved using Host interface rather than NAT machine properties.

Failed to retrieve file ‘core.db’ from mirror

If you receive this error message with the mirrors, try to define a different server name.

Understanding

What happens during package installation / update / removal

Tango-inaccurate.png The factual accuracy of this article or section is contested.Tango-inaccurate.png

When you successfully complete a package transaction, Pac Man performs the following high-level steps:

  1. Pac Man gets the package file to be installed for all packages in a transaction queue.
  2. Pac Man performs several checks that packages are likely to be installed.
  3. If pre-existing Pac Man PreTransaction hooks apply, they run.
  4. Each package is installed / updated / removed in turn.
    1. Se o pacote tiver um script de instalação, seu pre_install função é executada (ou pre_upgrade or pre_remove no caso de um pacote atualizado ou removido).
    2. pacman exclui todos os arquivos de uma versão pré-existente do pacote (no caso de um pacote atualizado ou removido). No entanto, os arquivos que foram marcados como arquivos de configuração no pacote são mantidos (consulte Pacman / Pacnew e Pacsave)
    3. pacman desmarca o pacote e despeja seus arquivos no sistema de arquivos (no caso de um pacote instalado ou atualizado). Os arquivos que sobrescreveriam os arquivos de configuração mantidos e modificados manualmente (consulte a etapa anterior) são armazenados com um novo nome (.pacnew).
    4. Se o pacote tiver um script de instalação, seu post_install função é executada (ou post_upgrade or post_remove no caso de um pacote atualizado ou removido).
  5. E se pacman PostTransaction ganchos existentes no final da transação, eles são executados.

See too


Paula Fonseca