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:

Listing changed backup files

If you want to backup your system configuration files you could copy all files in /etc/, but usually you are only interested in the files that you have changed. Modified backup files can be viewed with 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 /etc/sudoers) are included in the output.

Backup the pacman database

The following command can be used to backup 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 pacman_database.tar.bz2 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.

Tip: The pakbak-gitAUR package provides a script and a systemd service to automate the task. Configuration is possible in /etc/pakbak.conf.

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 pacologAUR. This utility lists recent commit messages for packages from the official repositories or the AUR, by using pacolog <package>.

2. Edit pacman.conf 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, 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:

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

Warning:repo-add adds the entries into the database in the same order as passed on the command line. If multiple versions of the same package are involved, care must be taken to ensure that the correct version is added last. In particular, note that lexical order used by the shell depends on the locale and differs from the vercmp ordering used by pacman.

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.xz' 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 pacman.conf for each system that is to use the repository. An example of a custom repository is in pacman.conf. 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 file:// url, or via FTP using ftp://localhost/path/to/directory.

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 standalone webserver which other computers can use as a first mirror:

You could also run darkhttpd as a systemd service for convenience. Just add this server at the top of your /etc/pacman.d/mirrorlist in client machines with Server = http://mymirror:8080. Make sure to keep your mirror updated.

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

Whichever web server you use, remember to open port 8080 to local traffic (and you probably want to deny anything not local), so add a rule like the following to iptables:

/etc/iptables/iptables.rules

-A TCP -s 192.168.0.0/16 -p tcp -m tcp --dport 8080 -j ACCEPT

Remember to restart iptables after making this change.

Distributed read-only cache

There are Arch-specific tools for automatically discovering other computers on your network offering a package cache. Try pacredir, pacserve, pkgdistcacheAUR, or paclanAUR. 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 /var/cache/pacman/ using any network-based mount protocol. This section shows how to use shfs or 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.

By default, smbfs does not serve filenames that contain colons, which results in the client downloading the offending package afresh. To prevent this, use the mapchars mount option on the client.

Then, to share the actual packages, mount /var/cache/pacman/pkg from the server to /var/cache/pacman/pkg on every client machine.

Warning: Do not make /var/cache/pacman/pkg or any of its ancestors (e.g., /var) a symlink. Pacman expects these to be directories. When pacman re-installs or upgrades itself, it will remove the symlinks and create empty directories instead. However during the transaction pacman relies on some files residing there, hence breaking the update process. Refer to FS#50298 for further details.

two-way with rsync

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

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

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 http://cache.domain.example:8080/ 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:

Use the nginx pacman cache config as a starting point for /etc/nginx/nginx.conf. Check that the resolver directive works for your needs. In the upstream server blocks, configure the proxy_pass directives with addresses of official mirrors, see examples in the config 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 mirrorlist file:

/etc/pacman.d/mirrorlist

Server = http://cache.domain.example:8080/$repo/os/$arch
...

Note: You will need to create a method to clear old packages, as the cache directory will continue to grow over time. paccache (which is provided by pacman-contrib) can be used to automate this using retention criteria of your choosing. For example, find /srv/http/pacman-cache/ -type d -exec paccache -v -r -k 2 -c {} \; will keep the last 2 versions of packages in your cache directory.

Synchronize pacman package cache using synchronization programs

Preventing unwanted cache purges

By default, pacman -Sc 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, add this entry in the [options] section of /etc/pacman.conf:

CleanMethod = KeepCurrent

Recreate a package from the file system

To recreate a package from the file system, use fakepkgAUR. 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 the explicitly installed packages can be useful, to backup a system for example or speed up installation on a new system:

$ pacman -Qqe > pkglist.txt

Note:

With option -t, the packages already required by other explicitly installed packages are not mentioned. If reinstalling from this list they will be installed but as dependencies only.

With option -n, foreign packages (e.g. from AUR) would be omitted from the list.

Use comm -13 <(pacman -Qqdt | sort) <(pacman -Qqdtt | sort) > optdeplist.txt to also create a list of the installed optional dependencies which can be reinstalled with --asdeps.

Use pacman -Qqem > foreignpkglist.txt to create the list of AUR and other foreign packages that have been explicitly installed.

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:

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:

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 pacutils:

Restore pacman's 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 /newarch)

Find applications that use libraries from older packages

Even if you installed a package the existing long-running programs (like daemons and servers) still keep using code from old package libraries. And it is a bad idea to let these programs running if the old library contains a security bug.

Here is a way how to find all the programs that use old packages code:

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

It will print running program name and old library that was removed or replaced with newer content.

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 localepurgeAUR, which runs after a package is installed to delete the unneeded locale files. A more direct approach is provided through the NoExtract directive in pacman.conf, which prevent these files from ever being installed. The example below installs English (US) files, or none at all:

Performance

Download speeds

Note: If your download speeds have been reduced to a crawl, ensure you are using one of the many mirrors and not ftp.archlinux.org, which is throttled since March 2007.

When downloading packages pacman uses the mirrors in the order they are in /etc/pacman.d/mirrorlist. 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 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 wget package then modify /etc/pacman.conf by uncommenting the following line in the [options] section:

XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u

Instead of uncommenting the wget parameters in /etc/pacman.conf, you can also modify the wget configuration file directly (the system-wide file is /etc/wgetrc, per user files are $HOME/.wgetrc.

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.

Note: Using aria2c in pacman's XferCommand will not result in parallel downloads of multiple packages. Pacman invokes the XferCommand with a single package at a time and waits for it to complete before invoking the next. To download multiple packages in parallel, see Powerpill.

Install aria2, then edit /etc/pacman.conf by adding the following line to the [options] section: