< Pacman

pacman/Tips and tricks

For general methods to improve the flexibility of the provided tips or pacman itself, see Core utilities and Bash.

Maintenance

Note: Instead of using comm (which requires sorted input with sort) in the sections below, you may also use grep -Fxf or grep -Fxvf.

See also System maintenance.

With version

You may want to get the list of installed packages with their version, which is useful when reporting bugs or discussing installed packages.

  • List all explicitly installed packages: pacman -Qe.
  • List all packages in the package group named group: pacman -Sg group
  • List all foreign packages (typically manually downloaded and installed or packages removed from the repositories): pacman -Qm.
  • List all native packages (installed from the sync database): .
  • List all explicitly installed native packages (i.e. present in the sync database) that are not direct or optional dependencies: .
  • List packages by regex: .
  • List packages by regex with custom output format (needs ): expac -s "%-30n %v" regex.

With size

Figuring out which packages are largest can be useful when trying to free space on your hard drive. There are two options here: get the size of individual packages, or get the size of packages and their dependencies.

Individual packages

The following command will list all installed packages and their individual sizes:

$ LC_ALL=C pacman -Qi | awk '/^Name/{name=$3} /^Installed Size/{print $4$5, name}' | sort -h
Packages and dependencies

To list package sizes with their dependencies,

  • Install and run .
  • Run pacgraph with the option.

To list the download size of several packages (leave blank to list all packages):

$ expac -S -H M '%k\t%n' packages

To list explicitly installed packages not in the meta package nor package group with size and description:

$ expac -H M "%011m\t%-20n\t%10d" $(comm -23 <(pacman -Qqen | sort) <({ pacman -Qqg base-devel; expac -l '\n' '%E' base; } | sort -u)) | sort -n

To list the packages marked for upgrade with their download size:

$ expac -S -H M '%k\t%n' $(pacman -Qqu) | sort -sh

To list optional dependencies only:

$ expac -S "%o" package

By date

To list the 20 last installed packages with , run:

$ expac --timefmt='%Y-%m-%d %T' '%l\t%n' | sort | tail -n 20

or, with seconds since the epoch (1970-01-01 UTC):

$ expac --timefmt=%s '%l\t%n' | sort -n | tail -n 20

Not in a specified group, repository or meta package

List explicitly installed packages not in the meta package:

$ comm -23 <(pacman -Qqe | sort) <(expac -l '\n' '%E' base | sort)

List explicitly installed packages not in the meta package or package group:

$ comm -23 <(pacman -Qqe | sort) <({ pacman -Qqg base-devel; expac -l '\n' '%E' base; } | sort -u)

List all installed packages unrequired by other packages, and which are not in the meta package or package group:

$ comm -23 <(pacman -Qqt | sort) <({ pacman -Qqg base-devel; echo base; } | sort -u)

As above, but with descriptions:

$ expac -H M '%-20n\t%10d' $(comm -23 <(pacman -Qqt | sort) <({ pacman -Qqg base-devel; echo base; } | sort -u))

List all installed packages that are not in the specified repository repo_name

$ comm -23 <(pacman -Qq | sort) <(pacman -Sql repo_name | sort)

List all installed packages that are in the repo_name repository:

$ comm -12 <(pacman -Qq | sort) <(pacman -Sql repo_name | sort)

List all packages on the Arch Linux ISO that are not in the meta package:

$ comm -23 <(curl https://gitlab.archlinux.org/archlinux/archiso/-/raw/master/configs/releng/packages.x86_64) <(expac -l '\n' '%E' base | sort)

Development packages

To list all development/unstable packages, run:

$ pacman -Qq | grep -Ee '-(bzr|cvs|darcs|git|hg|svn)

Browsing packages

To browse all installed packages with an instant preview of each package:

$ pacman -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pacman -Qil {} | less)'

This uses fzf to present a two-pane view listing all packages with package info shown on the right.

Enter letters to filter the list of packages; use arrow keys (or /) to navigate; press Enter to see package info under less.

To browse all packages currently known to pacman (both installed and not yet installed) in a similar way, using fzf, use:

$ pacman -Slq | fzf --preview 'pacman -Si {}' --layout=reverse

The navigational keybindings are the same, although Enter will not work in the same way.

Listing files owned by a package with size

This one might come in handy if you have found that a specific package uses a huge amount of space and you want to find out which files make up the most of that.

$ pacman -Qlq package | grep -v '/
| xargs -r du -h | sort -h

Identify files not owned by any package

If your system has stray files not owned by any package (a common case if you do not use the package manager to install software), you may want to find such files in order to clean them up.

One method is to use as the root user from which will list unowned files among other details.

Another is to list all files of interest and check them against pacman:

# find /etc /usr /opt | LC_ALL=C pacman -Qqo - 2>&1 >&- >/dev/null | cut -d ' ' -f 5-

Tracking unowned files created by packages

Most systems will slowly collect several ghost files such as state files, logs, indexes, etc. through the course of usual operation.

from  can be used to track these files and their associations via  (see ).

An example may look something like this (abridged):

/etc/pacreport.conf
[Options]
IgnoreUnowned = usr/share/applications/mimeinfo.cache

[PkgIgnoreUnowned]
alsa-utils = var/lib/alsa/asound.state
bluez = var/lib/bluetooth
ca-certificates = etc/ca-certificates/trust-source/*
dbus = var/lib/dbus/machine-id
glibc = etc/ld.so.cache
grub = boot/grub/*
linux = boot/initramfs-linux.img
pacman = var/lib/pacman/local
update-mime-database = usr/share/mime/magic

Then, when using as the root user, any unowned files will be listed if the associated package is no longer installed (or if any new files have been created).

Additionally, aconfmgr () allows tracking modified and orphaned files using a configuration script.

Removing unused packages (orphans)

Orphans are packages that were installed as a dependency and are no longer required by any package.

They can accumulate on your system over time either due to uninstalling packages using instead of , installing packages as makedepends, or packages removing dependencies in newer versions.

For recursively removing orphans and their configuration files:

# pacman -Qtdq | pacman -Rns -

If no orphans were found, the output is error: argument '-' specified with empty stdin. This is expected as no arguments were passed to .

Detecting more unneeded packages

In some cases the method above will not detect all possible unneeded packages. E.g. dependency cycles, excessive dependencies (fullfilled more than once), some unexplicit optionals etc.

To detect such packages:

$ pacman -Qqd | pacman -Rsu --print -

If you want to remove all packages in the list at once, run the command without argument.

Removing everything but essential packages

If it is ever necessary to remove all packages except the essentials packages, one method is to set the installation reason of the non-essential ones as dependency and then remove all unnecessary dependencies.

First, for all the packages "explicitly installed", change their installation reason to "installed as a dependency":

# pacman -D --asdeps $(pacman -Qqe)

Then, change the installation reason to "explicitly installed" of only the essential packages, those you do not want to remove, in order to avoid targeting them:

# pacman -D --asexplicit base linux linux-firmware

Finally, follow the instructions in #Removing unused packages (orphans) to remove all packages that are "installed as a dependency".

Getting the dependencies list of several packages

Dependencies are alphabetically sorted and doubles are removed.

$ LC_ALL=C pacman -Si packages | awk -F'[:<=>]' '/^Depends/ {print $2}' | xargs -n1 | sort -u

Alternatively, with :

$ expac -l '\n' %E -S packages | sort -u

Listing changed backup files

To list configuration files tracked by pacman as susceptible of containing user changes (i.e. files listed in the PKGBUILD backup array) and having received user modifications, use the following command:

# pacman -Qii | awk '/^MODIFIED/ {print $2}'

Running this command with root permissions will ensure that files readable only by root (such as ) are included in the output.

This can be used when doing a selective system backup or when trying to replicate a system configuration from one machine to another.

Tip: See #Listing all changed files from packages to list all changed files pacman knows about, not only backup files.

Back up the pacman database

The following command can be used to back up the local pacman database:

$ tar -cjf pacman_database.tar.bz2 /var/lib/pacman/local

Store the backup pacman database file on one or more offline media, such as a USB stick, external hard drive, or CD-R.

The database can be restored by moving the file into the directory and executing the following command:

# tar -xjvf pacman_database.tar.bz2
Note: If the pacman database files are corrupted, and there is no backup file available, there exists some hope of rebuilding the pacman database. Consult #Restore pacman's local database.

Check changelogs easily

When maintainers update packages, commits are often commented in a useful fashion. Users can quickly check these from the command line by installing . This utility lists recent commit messages for packages from the official repositories or the AUR, by using .

Installation and recovery

Alternative ways of getting and restoring packages.

Installing packages from a CD/DVD or USB stick

To download packages, or groups of packages:

# cd ~/Packages
# pacman -Syw --cachedir . base base-devel grub-bios xorg gimp
# repo-add ./custom.db.tar.gz ./*

Pacman, which will reference the host installation by default, will not properly resolve and download existing dependencies. In cases where all packages and dependencies are wanted, it is recommended to create a temporary blank DB and reference it with :

# mkdir /tmp/blankdb
# pacman -Syw --cachedir . --dbpath /tmp/blankdb base base-devel grub-bios xorg gimp
# repo-add ./custom.db.tar.gz ./*

Then you can burn the "Packages" directory to an optical disc (e.g. CD, DVD) or transfer it to a USB flash drive, external HDD, etc.

To install:

1. Mount the media:

For an optical disc drive:

# mount --mkdir /dev/sr0 /mnt/repo

For a USB flash drive, hard disk drive, etc.:

# mount --mkdir /dev/sdxY /mnt/repo

2. Edit and add this repository before the other ones (e.g. extra, core, etc.). This is important. Do not just uncomment the one on the bottom. This way it ensures that the files from the CD/DVD/USB take precedence over those in the standard repositories:

3. Finally, synchronize the pacman database to be able to use the new repository:

# pacman -Syu

Custom local repository

Use the repo-add script included with pacman to generate a database for a personal repository. Use repo-add --help for more details on its usage. A package database is a tar file, optionally compressed. Valid extensions are .db or .files followed by an archive extension of .tar, .tar.gz, .tar.bz2, .tar.xz, .tar.zst, or .tar.Z. The file does not need to exist, but all parent directories must exist.

To add a new package to the database, or to replace the old version of an existing package in the database, run:

$ repo-add /path/to/repo.db.tar.gz /path/to/package-1.0-1-x86_64.pkg.tar.zst

The database and the packages do not need to be in the same directory when using repo-add, but keep in mind that when using pacman with that database, they should be together. Storing all the built packages to be included in the repository in one directory also allows to use shell glob expansion to add or update multiple packages at once:

$ repo-add /path/to/repo.db.tar.gz /path/to/*.pkg.tar.zst

If you are looking to support multiple architectures then precautions should be taken to prevent errors from occurring. Each architecture should have its own directory tree:

The repo-add executable checks if the package is appropriate. If this is not the case you will be running into error messages similar to this:

==> ERROR: '/home/archie/customrepo/arch/foo-arch.pkg.tar.zst' does not have a valid database archive extension.

repo-remove is used to remove packages from the package database, except that only package names are specified on the command line.

$ repo-remove /path/to/repo.db.tar.gz pkgname

Once the local repository database has been created, add the repository to for each system that is to use the repository. An example of a custom repository is in . The repository's name is the database filename with the file extension omitted. In the case of the example above the repository's name would simply be repo. Reference the repository's location using a URL, or via FTP using ftp://localhost/path/to/directory.

If willing, add the custom repository to the list of unofficial user repositories, so that the community can benefit from it.

Network shared pacman cache

If you happen to run several Arch boxes on your LAN, you can share packages so that you can greatly decrease your download times. Keep in mind you should not share between different architectures (i.e. i686 and x86_64) or you will run into problems.

Read-only cache

If you are looking for a quick solution, you can simply run a basic temporary webserver which other computers can use as their first mirror.

First of all, make pacman databases available into the directory you will serve:

# ln -s /var/lib/pacman/sync/*.db /var/cache/pacman/pkg/

Then start serving this directory. For example, with Python http.server module:

$ python -m http.server -d /var/cache/pacman/pkg/
Tip: By default, Python http.server listens on port 8000 of any interface. To use another port, or bind only to specific address, simply add a parameter and an argument:
$ python -m http.server -d /var/cache/pacman/pkg/ --bind 127.0.0.1 8080

Then edit on each client machine to add this server as the top entry:

If looking for a more standalone solution, darkhttpd offers a very minimal webserver. Replace the previous command with e.g.:

$ sudo -u http darkhttpd /var/cache/pacman/pkg --no-server-id

You could also run darkhttpd as a systemd service for convenience: see Systemd#Writing unit files.

, a web small server written in Rust, can also be used:

$ miniserve /var/cache/pacman/pkg

Then edit as above with the first url miniserve is available at.

If you are already running a web server for some other purpose, you might wish to reuse that as your local repository server instead. For example, if you already serve a site with nginx, you can add an nginx server block listening on port 8080:

Remember to restart after making this change.

Overlay mount of read-only cache

It is possible to use one machine on a local network as a read-only package cache by overlay mounting its directory. Such a configuration is advantageous if this server has installed on it a reasonably comprehensive selection of up-to-date packages which are also used by other boxes. This is useful for maintaining a number of machines at the end of a low bandwidth upstream connection.

As an example, to use this method:

# mkdir /tmp/remote_pkg /mnt/workdir_pkg /tmp/pacman_pkg
# sshfs remote_username@remote_pkgcache_addr:/var/cache/pacman/pkg /tmp/remote_pkg -C
# mount -t overlay overlay -o lowerdir=/tmp/remote_pkg,upperdir=/var/cache/pacman/pkg,workdir=/mnt/workdir_pkg /tmp/pacman_pkg
Note: The working directory must be an empty directory on the same mounted device as the upper directory. See Overlay filesystem#Usage.

After this, run pacman using the option , e.g.:

# pacman -Syu --cachedir /tmp/pacman_pkg

Distributed read-only cache

There are Arch-specific tools for automatically discovering other computers on your network offering a package cache. Try pacredir, pacserve, , or . pkgdistcache uses Avahi instead of plain UDP which may work better in certain home networks that route instead of bridge between WiFi and Ethernet.

Historically, there was PkgD and multipkg, but they are no longer maintained.

Read-write cache

In order to share packages between multiple computers, simply share using any network-based mount protocol. This section shows how to use SSHFS to share a package cache plus the related library-directories between multiple computers on the same local network. Keep in mind that a network shared cache can be slow depending on the file-system choice, among other factors.

First, install any network-supporting filesystem packages: , , or nfs-utils.

Then, to share the actual packages, mount from the server to on every client machine.

two-way with rsync

Another approach in a local environment is rsync. Choose a server for caching and enable the rsync daemon. On clients synchronize two-way with this share via the rsync protocol. Filenames that contain colons are no problem for the rsync protocol.

Draft example for a client, using within the share name ensures an architecture-dependent sync:

 # rsync rsync://server/share_$(uname -m)/ /var/cache/pacman/pkg/ ...
 # pacman ...
 # paccache ...
 # rsync /var/cache/pacman/pkg/ rsync://server/share_$(uname -m)/  ...

Dynamic reverse proxy cache using nginx

nginx can be used to proxy package requests to official upstream mirrors and cache the results to the local disk. All subsequent requests for that package will be served directly from the local cache, minimizing the amount of internet traffic needed to update a large number of computers.

In this example, the cache server will run at and store the packages in /srv/http/pacman-cache/.

Install nginx on the computer that is going to host the cache. Create the directory for the cache and adjust the permissions so nginx can write files to it:

# mkdir /srv/http/pacman-cache
# chown http:http /srv/http/pacman-cache

Use the nginx pacman cache config as a starting point for . Check that the directive works for your needs. In the upstream server blocks, configure the directives with addresses of official mirrors, see examples in the configuration file about the expected format. Once you are satisfied with the configuration file start and enable nginx.

In order to use the cache each Arch Linux computer (including the one hosting the cache) must have the following line at the top of the file:

Pacoloco proxy cache server

Pacoloco is an easy-to-use proxy cache server for pacman repositories. It also allows automatic prefetching of the cached packages.

It can be installed as . Open the configuration file and add pacman mirrors:

/etc/pacoloco.yaml
port: 9129
repos:
  mycopy:
    urls:
      - http://mirror.lty.me/archlinux
      - http://mirrors.kernel.org/archlinux

Restart and the proxy repository will be available at .

Flexo proxy cache server

Flexo is yet another proxy cache server for pacman repositories. Flexo is available as . Once installed, start the flexo.service unit.

Flexo runs on port by default. Enter to the top of your so that pacman downloads packages via Flexo.

Synchronize pacman package cache using synchronization programs

Use Syncthing or Resilio Sync to synchronize the pacman cache directories (i.e. ).

Preventing unwanted cache purges

By default, removes package tarballs from the cache that correspond to packages that are not installed on the machine the command was issued on. Because pacman cannot predict what packages are installed on all machines that share the cache, it will end up deleting files that should not be.

To clean up the cache so that only outdated tarballs are deleted:

Recreate a package from the file system

To recreate a package from the file system, use . Files from the system are taken as they are, hence any modifications will be present in the assembled package. Distributing the recreated package is therefore discouraged; see ABS and Arch Linux Archive for alternatives.

List of installed packages

Keeping a list of all explicitly installed packages can be useful to backup a system or quicken the installation of a new one:

$ pacman -Qqe > pkglist.txt

To keep an up-to-date list of explicitly installed packages (e.g. in combination with a versioned /etc/), you can set up a hook. Example:

[Trigger]
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
When = PostTransaction
Exec = /bin/sh -c '/usr/bin/pacman -Qqe > /etc/pkglist.txt'

Install packages from a list

To install packages from a previously saved list of packages, while not reinstalling previously installed packages that are already up-to-date, run:

# pacman -S --needed - < pkglist.txt

However, it is likely foreign packages such as from the AUR or installed locally are present in the list. To filter out from the list the foreign packages, the previous command line can be enriched as follows:

# pacman -S --needed $(comm -12 <(pacman -Slq | sort) <(sort pkglist.txt))

Eventually, to make sure the installed packages of your system match the list and remove all the packages that are not mentioned in it:

# pacman -Rsu $(comm -23 <(pacman -Qq | sort) <(sort pkglist.txt))

Listing all changed files from packages

If you are suspecting file corruption (e.g. by software/hardware failure), but are unsure if files were corrupted, you might want to compare with the hash sums in the packages. This can be done with :

# paccheck --md5sum --quiet

For recovery of the database see #Restore pacman's local database. The files can also be extracted as from the respective package files.

Reinstalling all packages

To reinstall all native packages, use:

# pacman -Qqn | pacman -S -

Foreign (AUR) packages must be reinstalled separately; you can list them with .

Pacman preserves the installation reason by default.

Warning: To force all packages to be overwritten, use --overwrite=*, though this should be an absolute last resort. See System maintenance#Avoid certain pacman commands.

Restore pacman's local database

See pacman/Restore local database.

Recovering a USB key from existing install

If you have Arch installed on a USB key and manage to mess it up (e.g. removing it while it is still being written to), then it is possible to re-install all the packages and hopefully get it back up and working again (assuming USB key is mounted in )

# pacman -S $(pacman -Qq --dbpath /newarch/var/lib/pacman) --root /newarch --dbpath /newarch/var/lib/pacman

Viewing a single file inside a .pkg file

For example, if you want to see the contents of supplied within the package:

$ bsdtar -xOf /var/cache/pacman/pkg/systemd-250.4-2-x86_64.pkg.tar.zst etc/systemd/logind.conf

Or you can use vim to browse the archive:

$ vim /var/cache/pacman/pkg/systemd-250.4-2-x86_64.pkg.tar.zst

Find applications that use libraries from older packages

Already running processes do not automatically notice changes caused by updates. Instead, they continue using old library versions. That may be undesirable, due to potential issues related to security vulnerabilities or other bugs, and version incompatibility.

Processes depending on updated libraries may be found using either , which highlights the names of the affected programs, or with a snippet based on , which also prints the names of the libraries:

# lsof +c 0 | grep -w DEL | awk '1 { print $1 ": " $NF }' | sort -u

This solution will only detect files, that are normally kept opened by running processes, which basically limits it to shared libraries ( files). It may miss some dependencies, like those of Java or Python applications.

Installing only content in required languages

Many packages attempt to install documentation and translations in several languages. Some programs are designed to remove such unnecessary files, such as , which runs after a package is installed to delete the unneeded locale files. A more direct approach is provided through the directive in , which prevent these files from ever being installed.

Warning: Some users noted that removing locales has resulted in unintended consequences, even under Xorg.

The example below installs English (US) files, or none at all:

Installing packages on bad connection

When trying to install a package from a bad connection (e.g. a train using a cell phone), use the option to lessen the chance of receiving errors such as:

error: failed retrieving file […] Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds

or

error: failed retrieving file […] Operation timed out after 10014 milliseconds with 0 out of 0 bytes received

Performance

Download speeds

When downloading packages pacman uses the mirrors in the order they are in . The mirror which is at the top of the list by default however may not be the fastest for you. To select a faster mirror, see Mirrors.

Pacman's speed in downloading packages can also be improved by enabling parallel downloads, or by using a different application to download packages, instead of pacman's built-in file downloader.

In all cases, make sure you have the latest pacman before doing any modifications.

# pacman -Syu

Powerpill

Powerpill is a pacman wrapper that uses parallel and segmented downloading to try to speed up downloads for pacman.

wget

This is also very handy if you need more powerful proxy settings than pacman's built-in capabilities.

To use wget, first install the package then modify by uncommenting the following line in the section:

XferCommand = /usr/bin/wget --passive-ftp --show-progress -c -q -N %u

Instead of uncommenting the wget parameters in , you can also modify the wget configuration file directly (the system-wide file is , per user files are ).

aria2

aria2 is a lightweight download utility with support for resumable and segmented HTTP/HTTPS and FTP downloads. aria2 allows for multiple and simultaneous HTTP/HTTPS and FTP connections to an Arch mirror, which should result in an increase in download speeds for both file and package retrieval.

Install aria2, then edit by adding the following line to the section:

XferCommand = /usr/bin/aria2c --allow-overwrite=true --continue=true --file-allocation=none --log-level=error --max-tries=2 --max-connection-per-server=2 --max-file-not-found=5 --min-split-size=5M --no-conf --remote-time=true --summary-interval=60 --timeout=5 --dir=/ --out %o %u

See for used aria2c options.

  • : The directory to store the downloaded file(s) as specified by pacman.
  • : The output file name(s) of the downloaded file(s).
  • %o: Variable which represents the local filename(s) as specified by pacman.
  • : Variable which represents the download URL as specified by pacman.

Other applications

There are other downloading applications that you can use with pacman. Here they are, and their associated XferCommand settings:

Utilities

  • Lostfiles Script that identifies files not owned by any package.
https://github.com/graysky2/lostfiles || lostfiles
  • Powerpill Uses parallel and segmented downloading through aria2 and Reflector to try to speed up downloads for pacman.
https://xyne.dev/projects/powerpill/ || powerpillAUR

Graphical

  • Deepin App Store Third party app store for DDE built with DTK, using PackageKit. Supports AppStream metadata.
https://github.com/dekzi/dde-store || deepin-store
  • pcurses Curses TUI pacman wrapper written in C++.
https://github.com/schuay/pcurses || pcursesAUR
    gollark: Also, does anyone know why Linux booting would just hang after GRUB loads ramdisks and whatever?
    gollark: That would be fine, I think.
    gollark: It depends on sector I guess but you can probably also retrain.
    gollark: Your answer is unemployment?
    gollark: I can't read anything over 3 sentences, my laptop is beeing.
    This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.