Difference between revisions of "Pacman/Tips and tricks"

From ArchWiki
Jump to navigation Jump to search
(→‎Restore pacman's local database: added few minor notes)
(We are already using expac, so use that to enumerate dependencies of base too. pactree's recursive behavior is not wanted here anyway as it is not comparable to the previous pacman -Qqg base)
 
(745 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
 +
{{Lowercase title}}
 
[[Category:Package management]]
 
[[Category:Package management]]
[[es:Pacman Tips]]
+
[[es:Pacman (Español)/Tips and tricks]]
[[it:Pacman Tips]]
+
[[fa:Pacman tips]]
[[ru:Pacman Tips]]
+
[[fr:Pacman/Trucs et Astuces]]
[[tr:Pacman_ipuçları]]
+
[[it:Pacman/Tips and tricks]]
[[zh-CN:Pacman Tips]]
+
[[ja:Pacman ヒント]]
{{Article summary start|Summary}}
+
[[pt:Pacman (Português)/Tips and tricks]]
{{Article summary text|This is a collection of common tips for new pacman users.}}
+
[[ru:Pacman (Русский)/Tips and tricks]]
{{Article summary heading|Related}}
+
[[zh-hans:Pacman/Tips and tricks]]
{{Article summary wiki|pacman}}
+
{{Related articles start}}
{{Article summary wiki|Mirrors}}
+
{{Related|Mirrors}}
{{Article summary wiki|Creating Packages}}
+
{{Related|Creating packages}}
{{Article summary wiki|Custom local repository}}
+
{{Related articles end}}
{{Article summary end}}
+
For general methods to improve the flexibility of the provided tips or ''pacman'' itself, see [[Core utilities]] and [[Bash]].
  
==Cosmetic and Convienence==
+
== Maintenance ==
===Color output===
 
The most effective method of colorizing pacman is installing {{AUR|pacman-color}} from the [[AUR]].
 
  
{{Note|The package installs a separate pacman binary patched for colored output ({{ic|pacman-color}}), so you may want to use an [[alias]].}}
+
{{Expansion|{{ic|1=Usage=}} introduced with pacman 4.2, see [http://allanmcrae.com/2014/12/pacman-4-2-released/]}}
  
===Shortcuts===
+
{{Note|Instead of using ''comm'' (which requires sorted input with ''sort'') in the sections below, you may also use {{ic|grep -Fxf}} or {{ic|grep -Fxvf}}.}}
The following instructions allow users to run some of the more common pacman commands without the need to type them fully via a script alias.
 
  
====Configure the shell====
+
See also [[System maintenance]].
Add the following examples, which work in both [[Bash]] and [[Zsh]]:
 
{{bc|<nowiki> # Pacman alias examples
 
alias pacupg='sudo pacman -Syu'        # Synchronize with repositories before upgrading packages that are out of date on the local system.
 
alias pacin='sudo pacman -S'          # Install specific package(s) from the repositories
 
alias pacins='sudo pacman -U'          # Install specific package not from the repositories but from a file
 
alias pacre='sudo pacman -R'          # Remove the specified package(s), retaining its configuration(s) and required dependencies
 
alias pacrem='sudo pacman -Rns'        # Remove the specified package(s), its configuration(s) and unneeded dependencies
 
alias pacrep='pacman -Si'              # Display information about a given package in the repositories
 
alias pacreps='pacman -Ss'            # Search for package(s) in the repositories
 
alias pacloc='pacman -Qi'              # Display information about a given package in the local database
 
alias paclocs='pacman -Qs'            # Search for package(s) in the local database
 
  
# Additional pacman alias examples
+
=== Listing packages ===
  alias pacupd='sudo pacman -Sy && sudo abs'     # Update and refresh the local package and ABS databases against repositories
+
 
  alias pacinsd='sudo pacman -S --asdeps'       # Install given package(s) as dependencies of another package
+
You may want to get the list of installed packages with their version, which is useful when reporting bugs or discussing installed packages.
alias pacmir='sudo pacman -Syy'               # Force refresh of all package lists after updating /etc/pacman.d/mirrorlist
+
 
 +
* List all explicitly installed packages: {{ic|pacman -Qe}}.
 +
* List all packages in the [[package group]] named {{ic|''group''}}: {{ic|pacman -Sg ''group''}}
 +
* List all explicitly installed native packages (i.e. present in the sync database) that are not direct or optional dependencies: {{ic|pacman -Qent}}.
 +
* List all foreign packages (typically manually downloaded and installed or packages removed from the repositories): {{ic|pacman -Qm}}.
 +
* List all native packages (installed from the sync database(s)): {{ic|pacman -Qn}}.
 +
* List packages by regex: {{ic|pacman -Qs ''regex''}}.
 +
* List packages by regex with custom output format: {{ic|expac -s "%-30n %v" ''regex''}} (needs {{Pkg|expac}}).
 +
 
 +
==== 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 {{Pkg|expac}} and run {{ic|<nowiki>expac -H M '%m\t%n' | sort -h</nowiki>}}.
 +
* Run {{Pkg|pacgraph}} with the {{ic|-c}} option.
 +
 
 +
To list the download size of several packages (leave {{ic|''packages''}} blank to list all packages):
 +
 
 +
$ expac -S -H M '%k\t%n' ''packages''
 +
 
 +
To list explicitly installed packages not in the [[meta package]] {{Pkg|base}} nor [[package group]] {{Grp|base-devel}} 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 | uniq)) | sort -n
 +
 
 +
To list the packages marked for upgrade with their download size
 +
 
 +
$ pacman -Quq|xargs expac -S -H M '%k\t%n' | sort -sh
 +
 
 +
==== By date ====
 +
 
 +
To list the 20 last installed packages with {{Pkg|expac}}, 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 ====
 +
 
 +
{{Note|To get a list of packages installed as dependencies but no longer required by any installed package, see [[#Removing unused packages (orphans)]].}}
 +
 
 +
List explicitly installed packages not in the {{Pkg|base}} [[meta package]]:
 +
 
 +
$ comm -23 <(pacman -Qeq | sort) <(expac -l '\n' '%E' base | sort)
 +
 
 +
List explicitly installed packages not in the {{Pkg|base}} meta package or {{Grp|base-devel}} [[package group]]:
 +
 
 +
$ comm -23 <(pacman -Qeq | sort) <({ pacman -Qqg base-devel; expac -l '\n' '%E' base; } | sort | uniq)
 +
 
 +
List all installed packages unrequired by other packages, and which are not in the {{Pkg|base}} meta package or {{Grp|base-devel}} package group:
 +
 
 +
$ comm -23 <(pacman -Qqt | sort) <({ pacman -Qqg base-devel; expac -l '\n' '%E' base; } | sort | uniq)
 +
 
 +
As above, but with descriptions:
 +
 
 +
$ expac -HM '%-20n\t%10d' $(comm -23 <(pacman -Qqt | sort) <({ pacman -Qqg base-devel; expac -l '\n' '%E' base; } | sort | uniq))
 +
 
 +
List all installed packages that are ''not'' in the specified repository ''repo_name''
 +
 
 +
$ comm -23 <(pacman -Qq | sort) <(pacman -Slq ''repo_name'' | sort)
 +
 
 +
List all installed packages that are in the ''repo_name'' repository:
 +
 
 +
$ comm -12 <(pacman -Qq | sort) <(pacman -Slq ''repo_name'' | sort)
 +
 
 +
List all packages on the Arch Linux ISO that are not in the {{Pkg|base}} meta package:
 +
 
 +
<nowiki>$ comm -23 <(curl https://git.archlinux.org/archiso.git/tree/configs/releng/packages.x86_64) <(expac -l '\n' '%E' base | sort)</nowiki>
 +
 
 +
==== 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 {{ic|Ctrl-j}}/{{ic|Ctrl-k}}) to navigate; press {{ic|Enter}} to see package info under ''less''.
 +
 
 +
=== 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 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 [[Enhance system stability#Use the package manager to install software|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 {{ic|# pacreport --unowned-files}} from {{Pkg|pacutils}} 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 /var | LC_ALL=C pacman -Qqo - 2>&1 > /dev/null | cut -d ' ' -f 5-
 +
 
 +
{{Tip|The {{Pkg|lostfiles}} script performs similar steps, but also includes an extensive blacklist to remove common false positives from the output.}}
 +
 
 +
=== Tracking unowned files created by packages ===
 +
 
 +
Most systems will slowly collect several [http://ftp.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html#S3-RPM-INSIDE-FLIST-GHOST-DIRECTIVE ghost] files such as state files, logs, indexes, etc. through the course of usual operation.
 +
 
 +
{{ic|pacreport}} from {{Pkg|pacutils}} can be used to track these files and their associations via {{ic|/etc/pacreport.conf}} (see {{man|1|pacreport|FILES}}).
 +
 
 +
An example may look something like this (abridged):
 +
 
 +
{{hc|/etc/pacreport.conf|<nowiki>
 +
[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
 
</nowiki>}}
 
</nowiki>}}
  
====Usage====
+
Then, when using {{ic|# pacreport --unowned-files}}, any unowned files will be listed if the associated package is no longer installed (or if any new files have been created).
Perform the respective commands by simply typing the alias name. For example, to synchronize with repositories before upgrading packages that are out of date on the local system:
+
 
  $ pacupg
+
Additionally, [https://github.com/CyberShadow/aconfmgr aconfmgr] ({{AUR|aconfmgr-git}}) allows tracking modified and orphaned files using a configuration script.
Install packages from repositories:
+
 
$ pacin <package1> <package2> <package3>
+
=== Removing unused packages (orphans) ===
Install a custom built package:
+
 
$ pacins /path/to/<package>
+
For recursively removing orphans and their configuration files:
Completely remove a locally installed  package:
+
 
$ pacrem <package>
+
  # pacman -Rns $(pacman -Qtdq)
Search for available packages in the repositories:
+
 
$ pacreps <keywords>
+
If no orphans were found ''pacman'' outputs {{ic|error: no targets specified}}. This is expected as no arguments were passed to {{ic|pacman -Rns}}.
Display information about a package (e.g. size, dependencies) in the repositories:
+
 
  $ pacrep <keywords>
+
{{Note|The arguments {{ic|-Qt}} list only true orphans. To include packages which are ''optionally'' required by another package, pass the {{ic|-t}} flag twice (''i.e.'', {{ic|-Qtt}}).}}
 +
 
 +
=== 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 installed "as explicitly", change their installation reason to "as dependency":
 +
 
 +
  # pacman -D --asdeps $(pacman -Qqe)
  
====Notes====
+
Then, change the installation reason to "as explicitly" of only the essential packages, those you '''do not''' want to remove, in order to avoid targeting them:
The aliases used above are merely examples. By following the syntax samples above, rename the aliases as convenient. For example:
 
alias pacrem='sudo pacman -Rns'
 
alias pacout='sudo pacman -Rns'
 
  
In the case above, the commands {{Ic|pacrem}} and {{Ic|pacout}} both call Bash to execute the same command.
+
# pacman -D --asexplicit base linux linux-firmware
  
===Operations and Bash syntax===
+
{{Note|
In addition to pacman's standard set of features, there are ways to extend its usability through rudimentary [[Bash]] commands/syntax.
+
* Additional packages can be added to the above command in order to avoid being removed. See [[Installation guide#Install essential packages]] for more info on other packages that may be necessary for a fully functional base system.
 +
* This will also select the bootloader's package for removal. The system should still be bootable, but the boot parameters might not be changeable without it.
 +
}}
  
* To install a number of packages sharing similar patterns in their names -- not the entire group nor all matching packages; eg. {{Pkg|kde}}:
+
Finally, follow the instructions in [[#Removing unused packages (orphans)]] to remove all packages that have installation reason "as dependency".
pacman -S kde-{applets,theme,tools}
 
* Of course, that is not limited and can be expanded to however many levels needed:
 
pacman -S kde-{ui-{kde,kdemod},kdeartwork}
 
* Sometimes, {{Ic|-s}}'s builtin ERE 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:
 
pacman -Ss '^vim-'
 
* pacman has the {{Ic|-q}} operand to hide the version column, so it is possible to query and reinstall packages with "compiz" as part of their name:
 
pacman -S $(pacman -Qq | grep compiz)
 
  
==Maintenance==
+
=== Getting the dependencies list of several packages ===
''House keeping, in the interest of keeping a clean system and following [[The Arch Way]]''
 
  
===CacheClean to selectivly purge cache===
+
Dependencies are alphabetically sorted and doubles are removed.
[[CacheClean]] is a Python script to clean the {{ic|/var/cache/pacman/pkg}} directory while allowing to specify how many package versions should be retained. <sup>[http://bbs.archlinux.org/viewtopic.php?id=9104]</sup>
 
  
A corresponding {{AUR|Cacheclean}} package is also available from the [[AUR]].
+
{{Note|To only show the tree of local installed packages, use {{ic|pacman -Qi}}.}}
  
===Listing all installed packages with size===
+
$ LC_ALL=C pacman -Si ''packages'' | awk -F'[:<=>]' '/^Depends/ {print $2}' | xargs -n1 | sort -u
* You may want to get the list of installed packages sorted by size, which may be useful when freeing space on your hard drive.
 
pacman -Qi | awk '/^Name/ {pkg=$3} /Size/ {print $4$5,pkg}' | sort -n
 
* Use {{ic|pacsysclean}} from {{ic|pacman-contrib}} package.
 
* Install {{Pkg|expac}} and run {{ic| expac -s "%-30n %m" | sort -rhk 2}}
 
* Invoke pacgraph with the -c option to produce a list of all installed packages with their respective sizes on the system.  Pacgraph is available from [community].
 
  
===Identify files not owned by any package===
+
Alternatively, with {{Pkg|expac}}:  
Periodic checks for files outside of pacman database are recommended. These files are often some 3rd party applications installed using the usual procedure (e.g. {{ic|./configure && make && make install}}). Search the file-system for these files (or symlinks) using this simple script:
 
{{hc|pacman-disowned|2=
 
<nowiki>
 
#!/bin/sh
 
  
tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$
+
$ expac -l '\n' %E -S ''packages'' | sort -u
db=$tmp/db
 
fs=$tmp/fs
 
  
mkdir "$tmp"
+
=== Listing changed backup files ===
trap 'rm -rf "$tmp"' EXIT
 
  
pacman -Qlq | sort -u > "$db"
+
If you want to backup your system configuration files you could copy all files in {{ic|/etc/}}, but usually you are only interested in the files that you have changed. Modified [[Pacnew_and_Pacsave_files#Package_backup_files|backup files]] can be viewed with the following command:
  
find /bin /etc /lib /sbin /usr \
+
# pacman -Qii | awk '/^MODIFIED/ {print $2}'
  ! -name lost+found \
 
  \( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
 
  
comm -23 "$fs" "$db"
+
Running this command with root permissions will ensure that files readable only by root (such as {{ic|/etc/sudoers}}) are included in the output.
</nowiki>
+
 
}}
+
{{Tip|See [[#Listing all changed files from packages]] to list all changed files ''pacman'' knows about, not only backup files.}}
  
To generate the list:
+
=== Backup the pacman database ===
$ pacman-disowned > non-db.txt
 
  
Note that one should '''not''' delete all files listed in {{ic|non-db.txt}} without confirming each entry. There could be various configuration files, logs, etc., so use this list responsibly and only proceed after extensively searching for cross-references using {{Ic|grep}}.
+
The following command can be used to backup the local ''pacman'' database:
  
===Removing orphaned packages===
+
  $ tar -cjf pacman_database.tar.bz2 /var/lib/pacman/local
For ''recursively'' removing orphans:
 
  # pacman -Rs $(pacman -Qtdq)
 
  
The following function is easily inserted into {{ic|$HOME/.bashrc}} and removes orphans if found:
+
Store the backup ''pacman'' database file on one or more offline media, such as a USB stick, external hard drive, or CD-R.
  
<pre>orphans() {
+
The database can be restored by moving the {{ic|pacman_database.tar.bz2}} file into the {{ic|/}} directory and executing the following command:
  if [[ ! -n $(pacman -Qdt) ]]; then
 
    echo no orphans to remove
 
  else
 
    sudo pacman -Rs $(pacman -Qdtq)
 
  fi
 
}</pre>
 
  
===Removing everything but base group===
+
  # tar -xjvf pacman_database.tar.bz2
If it is ever necessary to remove all packages except the base group, try this one liner:
 
  {{bc|<nowiki># pacman -Rs $(comm -23 <(pacman -Qeq|sort) <((for i in $(pacman -Qqg base); do pactree -ul $i; done)|sort -u|cut -d ' ' -f 1))</nowiki>}}
 
  
Source: [https://bbs.archlinux.org/viewtopic.php?id=130176 Look at discussion here]
+
{{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]].}}
  
Notes:
+
{{Tip|The {{AUR|pakbak-git}} package provides a script and a [[systemd]] service to automate the task. Configuration is possible in {{ic|/etc/pakbak.conf}}.}}
# {{ic|comm}} requires sorted input otherwise you get e.g. {{ic|comm: file 1 is not in sorted order}}.
 
# {{ic|pactree}} prints the package name followed by what it provides e.g.
 
{{hc|$ pactree -lu logrotate|<nowiki>
 
logrotate
 
popt
 
glibc
 
linux-api-headers
 
tzdata
 
dcron cron
 
bash
 
readline
 
ncurses
 
gzip</nowiki>}}
 
The 'dcron cron' line seems to cause problems, that is why {{ic|cut -d ' ' -f 1}} is needed - to keep just the package name.
 
  
===Listing official installed packages only===
+
=== Check changelogs easily ===
A simple {{ic|diff}} will do it:
 
diff <(pacman -Qq | sort) <(pacman -Qmq | sort) --new-line-format=' --unchanged-group-format'%>'
 
  
===Getting the dependencies list of several packages===
+
When maintainers update packages, commits are often commented in a useful fashion. Users can quickly check these from the command line by installing {{AUR|pacolog}}. This utility lists recent commit messages for packages from the official repositories or the AUR, by using {{ic|pacolog <package>}}.
Dependencies are alphabetically sorted and doubles are removed.
 
Note that you can use {{ic|pacman -Qi}} to improve response time a little. But
 
you won't be able to query as many packages. Unfound packages are simply skiped
 
(hence the {{ic|2>/dev/null}}).
 
You can get dependencies of AUR packages as well if you use {{ic|yaourt -Si}},
 
but it will slow down the queries.
 
{{bc|<nowiki>
 
pacman -Si $@ 2>/dev/null | awk -F ": " -v filter="^Depends" \
 
'$0 ~ filter {gsub(/[>=<][^ ]*/,"",$2) ; gsub(/ +/,"\n",$2) ; print $2}' | sort -u</nowiki>}}
 
Alternatively, you can use {{ic|expac}}: {{ic|expac -l '\n' %E -S $@ &#124; sort -u}}
 
  
===Getting the size of several packages===
+
== Installation and recovery ==
You can use (and tweak) this little shell function:
 
{{bc|<nowiki>
 
pacman-size()
 
{
 
CMD="pacman -Si"
 
SEP=": "
 
TOTAL_SIZE=0
 
 
RESULT=$(eval "${CMD} $@ 2>/dev/null" | awk -F "$SEP" -v filter="^Size" -v pkg="^Name" \
 
  '$0 ~ pkg {pkgname=$2} $0 ~ filter {gsub(/\..*/,"") ; printf("%6s KiB %s\n", $2, pkgname)}' | sort -u -k3)
 
 
echo "$RESULT"
 
 
## Print total size.
 
echo "$RESULT" | awk '{TOTAL=$1+TOTAL} END {printf("Total : %d KiB\n",TOTAL)}'
 
}</nowiki>
 
}}
 
As told for the dependencies list, you can use {{ic|pacman -Qi}} instead, but
 
not [[yaourt]] since AUR's PKGBUILD do not have size information.
 
  
A nice one-liner:
+
Alternative ways of getting and restoring packages.
{{bc|<nowiki>
 
pacman -Si "$@" 2>/dev/null" | awk -F ": " -v filter="Size" -v pkg="Name" \
 
  '$0 ~ pkg {pkgname=$2} $0 ~ filter {gsub(/\..*/,"") ; printf("%6s KiB %s\n", $2, pkgname)}' | sort -u -k3 \
 
  | tee >(awk '{TOTAL=$1+TOTAL} END {printf("Total : %d KiB\n",TOTAL)}')</nowiki>
 
}}
 
You should replace "$@" with packages, or put this line in a shell function.
 
  
==Installation and recovery==
+
=== Installing packages from a CD/DVD or USB stick ===
''Alternative ways of getting and restoring packages''
 
  
===Installing packages from a CD/DVD or USB stick===
+
{{Merge|#Custom local repository|Use as an example and avoid duplication}}
  
 
To download packages, or groups of packages:
 
To download packages, or groups of packages:
Line 220: Line 263:
 
  # mount /dev/sdxY /mnt/repo  #For a USB stick.
 
  # mount /dev/sdxY /mnt/repo  #For a USB stick.
  
'''2.''' Edit {{ic|pacman.conf}} and add this repository ''before'' the other ones (e.g. extra, core, etc.). This is important. Don't just uncomment the one on the bottom. This way it ensures the files from the CD/DVD/USB take precedence over those in the standard repositories:
+
'''2.''' Edit {{ic|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:
  
{{hc|# nano /etc/pacman.conf|
+
{{hc|/etc/pacman.conf|2=
 
[custom]
 
[custom]
Server &#61; file:///mnt/repo/Packages}}
+
SigLevel = PackageRequired
 +
Server = file:///mnt/repo/Packages}}
 +
 
 +
'''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 {{ic|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.xz''
 +
 
 +
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 [https://www.archlinux.org/pacman/vercmp.8.html vercmp] ordering used by ''pacman''.}}
  
'''3.''' Finally, synchronize the pacman database to be able to use the new repository:
+
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:
  
# pacman -Sy
+
{{hc|$ tree ~/customrepo/ {{!}} sed "s/$(uname -m)/<arch>/g"|
 +
/home/archie/customrepo/
 +
└── <arch>
 +
    ├── customrepo.db -> customrepo.db.tar.xz
 +
    ├── customrepo.db.tar.xz
 +
    ├── customrepo.files -> customrepo.files.tar.xz
 +
    ├── customrepo.files.tar.xz
 +
    └── personal-website-git-b99cce0-1-<arch>.pkg.tar.xz
  
===Custom local repository===
+
1 directory, 5 files
pacman 3 introduced a new script named {{Ic|repo-add}} which makes generating a database for a personal repository much easier. Use {{Ic|repo-add --help}} for more details on its usage.
+
}}
  
Simply store all of the built packages to be included in the repository in one directory, and execute the following command (where ''repo'' is the name of the custom repository):
+
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:
$ repo-add /path/to/repo.db.tar.gz /path/to/*.pkg.tar.xz
 
  
Note that when using {{Ic|repo-add}}, the database and the packages do not need to be in the same directory. But when using pacman with that database, they should be together.
+
==> ERROR: '/home/archie/customrepo/<arch>/foo-<arch>.pkg.tar.xz' does not have a valid database archive extension.
  
To add a new package (and remove the old if it exists), run:
+
''repo-remove'' is used to remove packages from the package database, except that only package names are specified on the command line.
$ repo-add /path/to/repo.db.tar.gz /path/to/packagetoadd-1.0-1-i686.pkg.tar.xz
 
  
{{Note|If there is a package that needs to be removed from the repository, read up on {{Ic|repo-remove}}.}}
+
$ repo-remove ''/path/to/repo.db.tar.gz pkgname''
  
Once the local repository has been made, add the repository to {{ic|pacman.conf}}. The name of the {{ic|db.tar.gz}} file is the repository name. Reference it directly using a ''file://'' url, or access it via FTP using ftp://localhost/path/to/directory.
+
Once the local repository database has been created, add the repository to {{ic|pacman.conf}} for each system that is to use the repository. An example of a custom repository is in {{ic|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 {{ic|file://}} url, or via FTP using ftp://localhost/path/to/directory.
  
 
If willing, add the custom repository to the [[Unofficial user repositories|list of unofficial user repositories]], so that the community can benefit from it.
 
If willing, add the custom repository to the [[Unofficial user repositories|list of unofficial user repositories]], so that the community can benefit from it.
  
===Network shared pacman cache===
+
=== Network shared pacman cache ===
{{Tip|See [http://xyne.archlinux.ca/projects/pacserve/ pacserve] for an alternate solution.}}
+
{{Merge|Package_Proxy_Cache|Same topic}}
 +
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, e.g. {{Pkg|darkhttpd}}, which other computers can use as a first mirror:
 +
# ln -s /var/lib/pacman/sync/*.db /var/cache/pacman/pkg
 +
$ sudo -u http darkhttpd /var/cache/pacman/pkg --no-server-id
 +
You could also run darkhttpd as a systemd service for convenience. Just add this server at the top of your {{ic|/etc/pacman.d/mirrorlist}} in client machines with {{ic|1=Server = http&#58;//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:
 +
 
 +
{{hc|/etc/nginx/nginx.conf|
 +
server {
 +
    listen 8080;
 +
    root /var/cache/pacman/pkg;
 +
    server_name myarchrepo.localdomain;
 +
    try_files $uri $uri/;
 +
}
 +
}}
 +
 
 +
Remember to restart nginx after making this change.
 +
 
 +
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]]:
 +
 
 +
{{hc|/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 {{Pkg|pacredir}}, [[pacserve]], {{AUR|pkgdistcache}}, or {{AUR|paclan}}. 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 [https://bbs.archlinux.org/viewtopic.php?id=64391 PkgD] and [https://github.com/toofishes/multipkg multipkg], but they are no longer maintained.
  
In order to share packages between multiple computers, simply share {{ic|/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.
+
==== Read-write cache ====
  
First, install any network-supporting filesystem; for example [[sshfs]], [[shfs]], [[ftpfs]], [[smbfs]] or [[nfs]]
+
In order to share packages between multiple computers, simply share {{ic|/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.
{{Tip|To use sshfs or shfs, consider reading [[Using SSH Keys]].}}
+
 
 +
First, install any network-supporting filesystem packages: {{pkg|shfs-utils}}, {{pkg|sshfs}}, {{pkg|curlftpfs}}, {{pkg|samba}} or {{pkg|nfs-utils}}.
 +
 
 +
{{Tip|
 +
* To use ''sshfs'' or ''shfs'', consider reading [[Using SSH Keys]].
 +
* 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 {{ic|mapchars}} mount option on the client.
 +
}}
  
 
Then, to share the actual packages, mount {{ic|/var/cache/pacman/pkg}} from the server to {{ic|/var/cache/pacman/pkg}} on every client machine.
 
Then, to share the actual packages, mount {{ic|/var/cache/pacman/pkg}} from the server to {{ic|/var/cache/pacman/pkg}} on every client machine.
  
To have shared package databases, mount {{ic|<nowiki>/var/lib/pacman/sync/{core,extra,testing,community}</nowiki>}} in the same way. Proceed to place the appropriate lines in {{ic|/etc/fstab}}.
+
{{Warning|Do not make {{ic|/var/cache/pacman/pkg}} or any of its ancestors (e.g., {{ic|/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 {{bug|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 {{ic|uname -m}} within the share name ensures an architecture dependant 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 {{ic|<nowiki>http://cache.domain.example:8080/</nowiki>}} and store the packages in {{ic|/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 [https://github.com/nastasie-octavian/nginx_pacman_cache_config/blob/c54eca4776ff162ab492117b80be4df95880d0e2/nginx.conf nginx pacman cache config] as a starting point for {{ic|/etc/nginx/nginx.conf}}. Check that the {{ic|resolver}} directive works for your needs. In the upstream server blocks, configure the {{ic|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 [[Nginx#Running|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 {{ic|mirrorlist}} file:
 +
 
 +
{{hc|/etc/pacman.d/mirrorlist|<nowiki>
 +
Server = http://cache.domain.example:8080/$repo/os/$arch
 +
...
 +
</nowiki>}}
 +
 
 +
{{Note| You will need to create a method to clear old packages, as the cache directory will continue to grow over time. {{ic|paccache}} (which is provided by {{pkg|pacman-contrib}}) can be used to automate this using retention criteria of your choosing. For example, {{ic|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.}}
 +
 
 +
==== Pacoloco proxy cache server ====
 +
 
 +
[https://github.com/anatol/pacoloco Pacoloco] is an easy-to-use proxy cache server for pacman repositories. It can be installed as {{AUR|pacoloco-git}}. Open the configuration file and add pacman mirrors:
 +
 
 +
{{hc|/etc/pacoloco.yaml|<nowiki>
 +
port: 9129
 +
repos:
 +
  mycopy:
 +
    urls:
 +
      - http://mirror.lty.me/archlinux
 +
      - http://mirrors.kernel.org/archlinux
 +
</nowiki>}}
 +
 
 +
[[Restart]] {{ic|pacoloco.service}} and the proxy repository will be available at {{ic|http://<myserver>:9129/repo/mycopy}}.
 +
 
 +
==== Synchronize pacman package cache using synchronization programs ====
 +
 
 +
Use [[Syncthing]] or [[Resilio Sync]] to synchronize the ''pacman'' cache folders (i.e. {{ic|/var/cache/pacman/pkg}}).
 +
 
 +
==== Preventing unwanted cache purges ====
 +
 
 +
By default, {{Ic|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.
  
====Preventing unwanted cache purges====
+
To clean up the cache so that only ''outdated'' tarballs are deleted, add this entry in the {{ic|[options]}} section of {{ic|/etc/pacman.conf}}:
By default, {{Ic|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 {{Ic|[options]}} section of {{ic|/etc/pacman.conf}}:
 
 
  CleanMethod = KeepCurrent
 
  CleanMethod = KeepCurrent
  
===Backing up and retrieving a list of installed packages===
+
=== Recreate a package from the file system ===
It is good practice to keep periodic backups of all pacman-installed packages. In the event of a system crash which is unrecoverable by other   means, pacman can then easily reinstall the very same packages onto a new installation.
+
 
 +
To recreate a package from the file system, use {{AUR|fakepkg}}. 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 {{ic|-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 {{ic|-n}}, foreign packages (e.g. from [[AUR]]) would be omitted from the list.
 +
* Use {{ic|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 {{ic|--asdeps}}.
 +
* Use {{ic|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 {{ic|/etc/}}), you can set up a [[Pacman#Hooks|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))
  
*First, backup the current list of non-local packages:
+
{{Tip|These tasks can be automated. See {{AUR|bacpac}}, {{AUR|packup}}, {{AUR|pacmanity}}, and {{AUR|pug}} for examples.}}
$ comm -23 <(pacman -Qeq|sort) <(pacman -Qmq|sort) > pkglist
 
  
*Store the pkglist on a USB key or other convenient medium or gist.github.com or evernote or dropbox.
+
=== Listing all changed files from packages ===
  
*Copy the pkglist file to the new installation, and navigate to the directory containing it.
+
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 {{Pkg|pacutils}}:
  
*Issue the following command to install from the backup list:
+
  # paccheck --md5sum --quiet
  # pacman -S $(< pkglist)
 
  
 +
For recovery of the database see [[#Restore pacman's local database]]. The {{ic|mtree}} files can also be [[#Viewing a single file inside a .pkg file|extracted as {{ic|.MTREE}} from the respective package files]].
  
In the case you have a list which was not generated like mentioned above, there may be foreign packages in it (i.e. packages not belonging to any repos you have configured, or packages from the AUR).
+
{{Note|This should '''not''' be used as is when suspecting malicious changes! In this case security precautions such as using a live medium and an independent source for the hash sums are advised.}}
  
In such a case, you may still want to install all available packages from that list:
+
=== Reinstalling all packages ===
# pacman -S --needed $(comm -12 <(pacman -Slq|sort) <(sort badpkdlist) )
+
To reinstall all native packages, use:
Explanation:
 
* {{ic|pacman -Slq}} lists all available softwares, but the list is sorted by repository first, hence the ''sort'' command
 
* Sorted files are required in order to make the {{ic|comm}} command work.
 
* The {{ic|-12}} parameter display lines common to both entries.
 
* The {{ic|--needed}} switch is used to skip already installed packages.
 
  
You may also try to install all unavailable packages (those not in the repos) from the AUR using [[yaourt]] (not recommended unless you know exactly what you are doing):
+
  # pacman -Qqn | pacman -S -
  $ yaourt -S --needed $(comm -13 <(pacman -Slq|sort) <(sort badpkdlist) )
 
  
Finally, you may want to remove all the packages on your system that are not mentioned in the list.
+
Foreign (AUR) packages must be reinstalled separately; you can list them with {{ic|pacman -Qqm}}.
Warning: use this command wisely, and always check the result prompted by pacman.
 
# pacman -Rsu $(comm -23 <(pacman -Qq|sort) <(sort pkglist))
 
  
 +
''Pacman'' preserves the [[installation reason]] by default.
  
===List downloaded packages that are not in base or base-devel===
+
=== Restore pacman's local database ===
  
The following command will list any installed packages that are not in base/base-devel, and as such were likely installed manually by the user:
+
See [[Pacman/Restore local database]].
  
comm -23 <(pacman -Qeq|sort) <(pacman -Qgq base base-devel|sort)
+
=== Recovering a USB key from existing install ===
  
===Reinstalling all installed packages===
+
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 {{ic|/newarch}})
If you mess up your system ({{ic|rm -rf}}) you can repair by having pacman reinstall all of your packages.
 
  
If your system does not contain any foreign (AUR) packages you can run:
+
  # pacman -S $(pacman -Qq --dbpath /newarch/var/lib/pacman) --root /newarch --dbpath /newarch/var/lib/pacman
  # pacman -Qeq | pacman -S -
 
# pacman -Qdq | pacman -S --asdeps -
 
  
If you have foreign packages this will error as packages will not be found in the repositories. The following will make a list of all packages and remove the foreign packages seen with {{ic|pacman -Qmq}}. Combining a command to list all packages, and another to hide the list of foreign packages is required.
+
=== Viewing a single file inside a .pkg file ===
  
The following will reinstall every package found in the repositories, preserving asdeps/explicitly installed info:
+
For example, if you want to see the contents of {{ic|/etc/systemd/logind.conf}} supplied within the {{Pkg|systemd}} package:
# comm -23 <(pacman -Qeq|sort) <(pacman -Qmq|sort) | pacman -S -
 
# comm -23 <(pacman -Qdq|sort) <(pacman -Qmq|sort) | pacman -S --asdeps -
 
  
===Restore pacman's local database===
+
$ bsdtar -xOf /var/cache/pacman/pkg/systemd-204-3-x86_64.pkg.tar.xz etc/systemd/logind.conf
Signs that pacman needs a local database restoration:
 
*{{Ic|pacman -Q}} gives absolutely no output, and {{Ic|pacman -Syu}} erroneously reports that the system is up to date.
 
*When trying to install a package using {{Ic|pacman -S package}} it outputs a list of already satisfied dependencies.
 
*'''testdb''' (part of {{Pkg|pacman}}) reports database inconsistency
 
  
Most likely, pacman's database of installed software, {{ic|/var/lib/pacman/local}}, has been corrupted or deleted. While this is a serious problem, it can be restored by following the instructions below.
+
Or you can use {{pkg|vim}} to browse the archive:
  
Firstly, make sure pacman's log file is present:
+
  $ vim /var/cache/pacman/pkg/systemd-204-3-x86_64.pkg.tar.xz
  $ ls /var/log/pacman.log
 
  
If it does not exist, it is ''not'' possible to continue with this method. You may be able to use [http://bbs.archlinux.org/viewtopic.php?pid=670876 Xyne's package detection script] to recreate the database. If not, then the likely solution is to re-install the entire system.
+
=== Find applications that use libraries from older packages ===
  
====Log filter script====
+
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.
Create a script with the following content <sup>based on [http://bbs.archlinux.org/viewtopic.php?id=38531]</sup>:
 
{{hc|log2pkglist.awk|2=
 
<nowiki>
 
#!/usr/bin/awk -f
 
  
$3 == "removed" {
+
Here is a way how to find all the programs that use old packages code:
  pkg[$4] = 0
 
  next
 
}
 
  
$3 ~ /^(installed|upgraded)$/ {
+
# lsof +c 0 | grep -w DEL | awk '1 { print $1 ": " $NF }' | sort -u
  pkg[$4] = 1
+
It will print running program name and old library that was removed or replaced with newer content.
}
 
  
$6 == "->" {
+
=== Installing only content in required languages  ===
  pkgver[$4] = $7
 
  next
 
}
 
  
{
+
Many packages attempt to install documentation and translations in several languages. Some programs are designed to remove such unnecessary files, such as {{AUR|localepurge}}, which runs after a package is installed to delete the unneeded locale files. A more direct approach is provided through the {{ic|NoExtract}} directive in {{ic|pacman.conf}}, which prevent these files from ever being installed.
  pkgver[$4] = $5
 
}
 
  
END {
+
{{Warning|1=Some users noted that removing locales has resulted in [https://wiki.archlinux.org/index.php?title=Talk:Pacman&oldid=460285#Dangerous_NoExtract_example unintended consequences], even under [https://bbs.archlinux.org/viewtopic.php?id=250846 Xorg].}}
  for (i in pkg) if (pkg[i]) {
 
    pkgname = "" i "-" pkgver[i] "-*.pkg.tar.xz"
 
    gsub(/[()]/, "", pkgname)
 
  
    pkgcache = "/var/cache/pacman/pkg/"
+
The example below installs English (US) files, or none at all:
    custompkg = "/home/packages" # replace by location of your self-built packages
 
  
    if(!system("[ -f " custompkg pkgname " ]"))
+
{{hc|/etc/pacman.conf|2=
    {
+
NoExtract = usr/share/help/* !usr/share/help/en*
      print custompkg pkgname >> "files.list"
+
NoExtract = usr/share/gtk-doc/html/*
    }
+
NoExtract = usr/share/locale/* usr/share/X11/locale/* usr/share/i18n/* opt/google/chrome/locales/* !usr/share/X11/locale/C/*
    else if (!system("[ -f " pkgcache pkgname " ]"))
+
NoExtract = !*locale*/en*/* !usr/share/i18n/charmaps/UTF-8.gz !usr/share/*locale*/locale.*
    {
+
NoExtract = !usr/share/*locales/en_?? !usr/share/*locales/i18n* !usr/share/*locales/iso*
      print pkgcache pkgname >> "files.list"
+
NoExtract = !usr/share/*locales/trans*
    }
+
NoExtract = usr/share/qt4/translations/*
    else
+
NoExtract = usr/share/man/* !usr/share/man/man*
    {
+
NoExtract = usr/share/vim/vim*/lang/*
      print i
+
NoExtract = usr/lib/libreoffice/help/en-US/*
    }
 
  }
 
}
 
</nowiki>
 
 
}}
 
}}
 
Make the script executable:
 
$ chmod +x log2pkglist.awk
 
  
====Generating the package recovery list====
+
== Performance ==
{{Warning|If for some reason your [[pacman]] cache or [[makepkg]] package destination contain packages for other architectures, remove them before continuation.}}
+
 
 +
=== 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 [https://www.archlinux.org/news/302/ throttled since  March 2007].}}
 +
 
 +
When downloading packages ''pacman'' uses the mirrors in the order they are in {{ic|/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''<nowiki>'</nowiki>s speed in downloading packages can also be improved by using a different application to download packages, instead of ''pacman''<nowiki>'</nowiki>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''<nowiki>'</nowiki>s built-in capabilities.  
  
Run the script:
+
To use {{ic|wget}}, first [[install]] the {{Pkg|wget}} package then modify {{ic|/etc/pacman.conf}} by uncommenting the following line in the {{ic|[options]}} section:
$ ./log2pkglist.awk /var/log/pacman.log > pkglist.orig
 
  
This way two files will be created: {{Ic|files.list}} with package files, still present on machine and {{Ic|pkglist.orig}}, packages from which should be downloaded. Later operation may result in mismatch between files of older versions of package, still present on machine, and files, found in new version. Such mismatches will have to be fixed manually.
+
XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
  
Here is a way to automatically restrict second list to packages available in a repository:
+
Instead of uncommenting the {{ic|wget}} parameters in {{ic|/etc/pacman.conf}}, you can also modify the {{ic|wget}} configuration file directly (the system-wide file is {{ic|/etc/wgetrc}}, per user files are {{ic|$HOME/.wgetrc}}.
$ { cat pkglist.orig; pacman -Slq; } | sort | uniq -d > pkglist
 
  
Check if some important ''base'' package are missing, and add them to the list:
+
==== aria2 ====
$ comm -23 <(pacman -Sgq base) pkglist.orig >> pkglist
 
  
Proceed once the contents of both lists are satisfactory, since they will be used to restore pacman's installed package database; {{ic|/var/lib/pacman/local/}}.
+
[[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.
  
====Performing the recovery====
+
{{Note|Using aria2c in ''pacman''<nowiki>'</nowiki>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]].}}
Define bash alias for recovery purposes:
 
  
{{bc|1=
+
Install {{Pkg|aria2}}, then edit {{ic|/etc/pacman.conf}} by adding the following line to the {{ic|[options]}} section:
# recovery-pacman() {
+
 
    pacman "$@"      \
+
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
    --log /dev/null  \
 
    --noscriptlet    \
 
    --dbonly          \
 
    --force          \
 
    --nodeps          \
 
    --needed          \
 
    #
 
}
 
}}
 
  
{{Ic|--log /dev/null}} allows to avoid needless pollution of pacman log, {{Ic|--needed}} will save some time by skipping packages, already present in database, {{Ic|--nodeps}} will allow installation of cached packages, even if packages being installed depend on newer versions. Rest of options will allow '''pacman''' to operate without reading/writing filesystem.
+
{{Tip|1=[https://bbs.archlinux.org/viewtopic.php?pid=1491879#p1491879 This alternative configuration for using ''pacman'' with aria2] tries to simplify configuration and adds more configuration options.}}
  
Populate the sync database:
+
See [http://aria2.sourceforge.net/manual/en/html/aria2c.html#options OPTIONS] in {{man|1|aria2c}} for used aria2c options.
# pacman -Sy
 
  
Start database generation by installing locally available package files from {{ic|files.list}}:
+
* {{ic|-d, --dir}}: The directory to store the downloaded file(s) as specified by ''pacman''.
# recovery-pacman -U $(< files.list)
+
* {{ic|-o, --out}}: The output file name(s) of the downloaded file(s).  
 +
* {{ic|%o}}: Variable which represents the local filename(s) as specified by ''pacman''.
 +
* {{ic|%u}}: Variable which represents the download URL as specified by ''pacman''.
  
Install the rest from {{ic|pkglist}}:
+
==== Other applications ====
# recovery-pacman -S $(< pkglist)
 
  
Update the local database so that packages that are not required by any other package are marked as explicitly installed and the other as dependences. You will need be extra careful in the future when removing packages, but with the original database lost is the best we can do.
+
There are other downloading applications that you can use with ''pacman''. Here they are, and their associated XferCommand settings:
# pacman -D --asdeps $(pacman -Qq)
 
# pacman -D --asexplicit $(pacman -Qtq)
 
  
Optionally check all installed packages for corruption:
+
* {{ic|snarf}}: {{ic|1=XferCommand = /usr/bin/snarf -N %u}}
# pacman -Qk
+
* {{ic|lftp}}: {{ic|1=XferCommand = /usr/bin/lftp -c pget %u}}
 +
* {{ic|axel}}: {{ic|1=XferCommand = /usr/bin/axel -n 2 -v -a -o %o %u}}
 +
* {{ic|hget}}: {{ic|1=XferCommand = /usr/bin/hget %u -n 2 -skip-tls false}} (please read the [https://github.com/huydx/hget documentation on the Github project page] for more info)
  
Optionally [[#Identify files not owned by any package]].
+
== Utilities ==
  
Update all packages:
+
* {{App|Lostfiles|Script that identifies files not owned by any package.|https://github.com/graysky2/lostfiles|{{Pkg|lostfiles}}}}
pacman -Su
+
* {{App|Pacmatic|''Pacman'' wrapper to check Arch News before upgrading, avoid partial upgrades, and warn about configuration file changes.|http://kmkeen.com/pacmatic|{{Pkg|pacmatic}}}}
 +
* {{App|pacutils|Helper library for libalpm based programs.|https://github.com/andrewgregory/pacutils|{{Pkg|pacutils}}}}
 +
* {{App|[[pkgfile]]|Tool that finds what package owns a file.|http://github.com/falconindy/pkgfile|{{Pkg|pkgfile}}}}
 +
* {{App|pkgtools|Collection of scripts for Arch Linux packages.|https://github.com/Daenyth/pkgtools|{{AUR|pkgtools}}}}
 +
* {{App|pkgtop|Interactive package manager and resource monitor designed for the GNU/Linux.|https://github.com/orhun/pkgtop|{{AUR|pkgtop-git}}}}
 +
* {{App|[[Powerpill]]|Uses parallel and segmented downloading through [[aria2]] and [[Reflector]] to try to speed up downloads for ''pacman''.|https://xyne.archlinux.ca/projects/powerpill/|{{AUR|powerpill}}}}
 +
* {{App|repoctl|Tool to help manage local repositories.|https://github.com/cassava/repoctl|{{AUR|repoctl}}}}
 +
* {{App|repose|An Arch Linux repository building tool.|https://github.com/vodik/repose|{{Pkg|repose}}}}
 +
* {{App|[[Snapper#Wrapping_pacman_transactions_in_snapshots|snap-pac]]|Make ''pacman'' automatically use snapper to create pre/post snapshots like openSUSE's YaST.|https://github.com/wesbarnett/snap-pac|{{pkg|snap-pac}}}}
 +
* {{App|vrms-arch|A virtual Richard M. Stallman to tell you which non-free packages are installed.|https://github.com/orospakr/vrms-arch|{{AUR|vrms-arch}}}}
  
===Recovering a USB key from existing install===
+
=== Graphical ===
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)
 
# pacman -S $(pacman -Qq --dbpath /newarch/var/lib/pacman) --root /newarch --dbpath /newarch/var/lib/pacman
 
  
===Extracting contents of a .pkg file===
+
{{Warning|PackageKit opens up system permissions by default, and is otherwise not recommended for general usage. See {{Bug|50459}} and {{Bug|57943}}.}}
The {{ic|.pkg}} files ending in {{ic|.xz}} are simply tar'ed archives that can be decompressed with:
 
$ tar -Jxvf package.tar.xz
 
If you want to extract a couple of files out of a {{ic|.pkg}} file, this would be a way to do it.
 
  
===Viewing a single file inside a .pkg file===
+
* {{App|Apper|Qt 5 application and package manager using PackageKit written in C++. Supports [https://www.freedesktop.org/wiki/Distributions/AppStream/ AppStream metadata].|https://userbase.kde.org/Apper|{{Pkg|apper}}}}
for example, if you want to see the contents of "/etc/conf.d/ntpd.conf" supplied within the ntp package:
+
* {{App|Discover|Qt 5 application manager using PackageKit written in C++/QML. Supports [https://www.freedesktop.org/wiki/Distributions/AppStream/ AppStream metadata], [[Flatpak]] and [[fwupd|firmware updates]]. |https://userbase.kde.org/Discover|{{Pkg|discover}}}}
$ tar -xOf /var/cache/pacman/pkg/ntp-4.2.6.p5-6-i686.pkg.tar.xz etc/conf.d/ntpd.conf
+
* {{App|GNOME PackageKit|GTK 3 package manager using PackageKit written in C.|https://freedesktop.org/software/PackageKit/|{{Pkg|gnome-packagekit}}}}
 +
* {{App|GNOME Software|GTK 3 application manager using PackageKit written in C. Supports [https://www.freedesktop.org/wiki/Distributions/AppStream/ AppStream metadata], [[Flatpak]] and [[fwupd|firmware updates]]. |https://wiki.gnome.org/Apps/Software|{{pkg|gnome-software}}}}
 +
* {{App|pcurses|Curses TUI pacman wrapper written in C++.|https://github.com/schuay/pcurses|{{Pkg|pcurses}}}}
 +
* {{App|tkPacman|Tk pacman wrapper written in Tcl.|https://sourceforge.net/projects/tkpacman|{{AUR|tkpacman}}}}

Latest revision as of 20:46, 23 February 2020

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

Contents

Maintenance

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Usage= introduced with pacman 4.2, see [1] (Discuss in Talk:Pacman/Tips and tricks#)
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.

Listing packages

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 explicitly installed native packages (i.e. present in the sync database) that are not direct or optional dependencies: pacman -Qent.
  • 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(s)): pacman -Qn.
  • List packages by regex: pacman -Qs regex.
  • List packages by regex with custom output format: expac -s "%-30n %v" regex (needs expac).

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 expac and run expac -H M '%m\t%n' | sort -h.
  • Run pacgraph with the -c option.

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

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

To list explicitly installed packages not in the meta package base nor package group base-devel 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 | uniq)) | sort -n

To list the packages marked for upgrade with their download size

$ pacman -Quq|xargs expac -S -H M '%k\t%n' | sort -sh

By date

To list the 20 last installed packages with expac, 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

Note: To get a list of packages installed as dependencies but no longer required by any installed package, see #Removing unused packages (orphans).

List explicitly installed packages not in the base meta package:

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

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

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

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

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

As above, but with descriptions:

$ expac -HM '%-20n\t%10d' $(comm -23 <(pacman -Qqt | sort) <({ pacman -Qqg base-devel; expac -l '\n' '%E' base; } | sort | uniq))

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

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

List all installed packages that are in the repo_name repository:

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

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

$ comm -23 <(curl https://git.archlinux.org/archiso.git/tree/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 Ctrl-j/Ctrl-k) to navigate; press Enter to see package info under less.

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 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 # pacreport --unowned-files from pacutils 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 /var | LC_ALL=C pacman -Qqo - 2>&1 > /dev/null | cut -d ' ' -f 5-
Tip: The lostfiles script performs similar steps, but also includes an extensive blacklist to remove common false positives from the output.

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.

pacreport from pacutils can be used to track these files and their associations via /etc/pacreport.conf (see pacreport(1)).

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 # pacreport --unowned-files, any unowned files will be listed if the associated package is no longer installed (or if any new files have been created).

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

Removing unused packages (orphans)

For recursively removing orphans and their configuration files:

# pacman -Rns $(pacman -Qtdq)

If no orphans were found pacman outputs error: no targets specified. This is expected as no arguments were passed to pacman -Rns.

Note: The arguments -Qt list only true orphans. To include packages which are optionally required by another package, pass the -t flag twice (i.e., -Qtt).

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 installed "as explicitly", change their installation reason to "as dependency":

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

Then, change the installation reason to "as explicitly" 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
Note:
  • Additional packages can be added to the above command in order to avoid being removed. See Installation guide#Install essential packages for more info on other packages that may be necessary for a fully functional base system.
  • This will also select the bootloader's package for removal. The system should still be bootable, but the boot parameters might not be changeable without it.

Finally, follow the instructions in #Removing unused packages (orphans) to remove all packages that have installation reason "as dependency".

Getting the dependencies list of several packages

Dependencies are alphabetically sorted and doubles are removed.

Note: To only show the tree of local installed packages, use pacman -Qi.
$ LC_ALL=C pacman -Si packages | awk -F'[:<=>]' '/^Depends/ {print $2}' | xargs -n1 | sort -u

Alternatively, with expac:

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

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.

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

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

Installation and recovery

Alternative ways of getting and restoring packages.

Installing packages from a CD/DVD or USB stick

Merge-arrows-2.pngThis article or section is a candidate for merging with #Custom local repository.Merge-arrows-2.png

Notes: Use as an example and avoid duplication (Discuss in Talk:Pacman/Tips and tricks#)

To download packages, or groups of packages:

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

Then you can burn the "Packages" folder to a CD/DVD or transfer it to a USB stick, external HDD, etc.

To install:

1. Mount the media:

# mkdir /mnt/repo
# mount /dev/sr0 /mnt/repo    #For a CD/DVD.
# mount /dev/sdxY /mnt/repo   #For a USB stick.

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:

/etc/pacman.conf
[custom]
SigLevel = PackageRequired
Server = file:///mnt/repo/Packages

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

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:

$ tree ~/customrepo/ | sed "s/$(uname -m)/<arch>/g"
/home/archie/customrepo/
└── <arch>
    ├── customrepo.db -> customrepo.db.tar.xz
    ├── customrepo.db.tar.xz
    ├── customrepo.files -> customrepo.files.tar.xz
    ├── customrepo.files.tar.xz
    └── personal-website-git-b99cce0-1-<arch>.pkg.tar.xz

1 directory, 5 files

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.

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

Merge-arrows-2.pngThis article or section is a candidate for merging with Package_Proxy_Cache.Merge-arrows-2.png

Notes: Same topic (Discuss in Talk:Pacman/Tips and tricks#)

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, e.g. darkhttpd, which other computers can use as a first mirror:

# ln -s /var/lib/pacman/sync/*.db /var/cache/pacman/pkg
$ sudo -u http darkhttpd /var/cache/pacman/pkg --no-server-id

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:

/etc/nginx/nginx.conf
server {
    listen 8080;
    root /var/cache/pacman/pkg;
    server_name myarchrepo.localdomain;
    try_files $uri $uri/;
}

Remember to restart nginx after making this change.

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.

First, install any network-supporting filesystem packages: shfs-utils, sshfs, curlftpfs, samba or nfs-utils.

Tip:
  • To use sshfs or shfs, consider reading Using SSH Keys.
  • 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:

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

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

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.

Pacoloco proxy cache server

Pacoloco is an easy-to-use proxy cache server for pacman repositories. It can be installed as pacoloco-gitAUR. 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 pacoloco.service and the proxy repository will be available at http://<myserver>:9129/repo/mycopy.

Synchronize pacman package cache using synchronization programs

Use Syncthing or Resilio Sync to synchronize the pacman cache folders (i.e. /var/cache/pacman/pkg).

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:

[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))
Tip: These tasks can be automated. See bacpacAUR, packupAUR, pacmanityAUR, and pugAUR for examples.

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:

# paccheck --md5sum --quiet

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

Note: This should not be used as is when suspecting malicious changes! In this case security precautions such as using a live medium and an independent source for the hash sums are advised.

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

Pacman preserves the installation reason by default.

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 /newarch)

# 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 /etc/systemd/logind.conf supplied within the systemd package:

$ bsdtar -xOf /var/cache/pacman/pkg/systemd-204-3-x86_64.pkg.tar.xz etc/systemd/logind.conf

Or you can use vim to browse the archive:

$ vim /var/cache/pacman/pkg/systemd-204-3-x86_64.pkg.tar.xz

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.

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:

/etc/pacman.conf
NoExtract = usr/share/help/* !usr/share/help/en*
NoExtract = usr/share/gtk-doc/html/*
NoExtract = usr/share/locale/* usr/share/X11/locale/* usr/share/i18n/* opt/google/chrome/locales/* !usr/share/X11/locale/C/*
NoExtract = !*locale*/en*/* !usr/share/i18n/charmaps/UTF-8.gz !usr/share/*locale*/locale.*
NoExtract = !usr/share/*locales/en_?? !usr/share/*locales/i18n* !usr/share/*locales/iso*
NoExtract = !usr/share/*locales/trans*
NoExtract = usr/share/qt4/translations/*
NoExtract = usr/share/man/* !usr/share/man/man*
NoExtract = usr/share/vim/vim*/lang/*
NoExtract = usr/lib/libreoffice/help/en-US/*

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:

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
Tip: This alternative configuration for using pacman with aria2 tries to simplify configuration and adds more configuration options.

See OPTIONS in aria2c(1) for used aria2c options.

  • -d, --dir: The directory to store the downloaded file(s) as specified by pacman.
  • -o, --out: The output file name(s) of the downloaded file(s).
  • %o: Variable which represents the local filename(s) as specified by pacman.
  • %u: 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:

  • snarf: XferCommand = /usr/bin/snarf -N %u
  • lftp: XferCommand = /usr/bin/lftp -c pget %u
  • axel: XferCommand = /usr/bin/axel -n 2 -v -a -o %o %u
  • hget: XferCommand = /usr/bin/hget %u -n 2 -skip-tls false (please read the documentation on the Github project page for more info)

Utilities

  • Lostfiles — Script that identifies files not owned by any package.
https://github.com/graysky2/lostfiles || lostfiles
  • PacmaticPacman wrapper to check Arch News before upgrading, avoid partial upgrades, and warn about configuration file changes.
http://kmkeen.com/pacmatic || pacmatic
  • pacutils — Helper library for libalpm based programs.
https://github.com/andrewgregory/pacutils || pacutils
  • pkgfile — Tool that finds what package owns a file.
http://github.com/falconindy/pkgfile || pkgfile
  • pkgtools — Collection of scripts for Arch Linux packages.
https://github.com/Daenyth/pkgtools || pkgtoolsAUR
  • pkgtop — Interactive package manager and resource monitor designed for the GNU/Linux.
https://github.com/orhun/pkgtop || pkgtop-gitAUR
  • Powerpill — Uses parallel and segmented downloading through aria2 and Reflector to try to speed up downloads for pacman.
https://xyne.archlinux.ca/projects/powerpill/ || powerpillAUR
  • repoctl — Tool to help manage local repositories.
https://github.com/cassava/repoctl || repoctlAUR
  • repose — An Arch Linux repository building tool.
https://github.com/vodik/repose || repose
  • snap-pac — Make pacman automatically use snapper to create pre/post snapshots like openSUSE's YaST.
https://github.com/wesbarnett/snap-pac || snap-pac
  • vrms-arch — A virtual Richard M. Stallman to tell you which non-free packages are installed.
https://github.com/orospakr/vrms-arch || vrms-archAUR

Graphical

Warning: PackageKit opens up system permissions by default, and is otherwise not recommended for general usage. See FS#50459 and FS#57943.
  • Apper — Qt 5 application and package manager using PackageKit written in C++. Supports AppStream metadata.
https://userbase.kde.org/Apper || apper
https://userbase.kde.org/Discover || discover
  • GNOME PackageKit — GTK 3 package manager using PackageKit written in C.
https://freedesktop.org/software/PackageKit/ || gnome-packagekit
https://wiki.gnome.org/Apps/Software || gnome-software
  • pcurses — Curses TUI pacman wrapper written in C++.
https://github.com/schuay/pcurses || pcurses
  • tkPacman — Tk pacman wrapper written in Tcl.
https://sourceforge.net/projects/tkpacman || tkpacmanAUR