Difference between revisions of "Pacman/Tips and tricks"

From ArchWiki
Jump to: navigation, search
m (Changed variable misspell and changed .path file location to system Directory.)
(Removing unused packages (orphans): move newly added content to the end and flag it for merging with pacman#Installation reason)
 
(370 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/Tips and tricks]]
[[it:Pacman Tips]]
+
[[fr:Astuces Pacman]]
[[ru:Pacman Tips]]
+
[[it:Pacman/Tips and tricks]]
[[tr:Pacman_ipuçları]]
+
[[ja:Pacman ヒント]]
[[zh-CN:Pacman Tips]]
+
[[ru:Pacman/Tips and tricks]]
{{Article summary start|Summary}}
+
[[tr:Pacman ipuçları]]
{{Article summary text|This is a collection of common tips for new pacman users.}}
+
[[zh-cn:Pacman/Tips and tricks]]
{{Article summary heading|Related}}
+
{{Related articles start}}
{{Article summary wiki|pacman}}
+
{{Related|pacman}}
{{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}}
+
See [[pacman]] for the main article.
  
== Cosmetic and Convienence ==
+
For general methods to improve the flexibility of the provided tips or pacman itself, see [[Core utilities]] and [[Bash]].
  
=== Color output ===
+
== Cosmetic and convenience ==
  
The most effective method of colorizing pacman is installing {{AUR|pacman-color}} from the [[AUR]].
+
=== Graphical front-ends ===
  
{{Note|The package installs a separate pacman binary patched for colored output ({{ic|pacman-color}})}}
+
* {{App|Discover|A collection of package management tools for KDE, using PackageKit.|https://projects.kde.org/projects/kde/workspace/discover|{{Pkg|discover}}}}
 +
* {{App|GNOME packagekit|GTK based package management tool|http://www.freedesktop.org/software/PackageKit/|{{Pkg|gnome-packagekit}}}}
 +
* {{App|GNOME Software|Gnome Software App. (Curated selection for GNOME)|https://wiki.gnome.org/Apps/Software|{{pkg|gnome-software}}}}
 +
* {{App|pcurses|Package management in a curses frontend|https://github.com/schuay/pcurses|{{Pkg|pcurses}}}}
 +
* {{App|tkPacman|Depends only on Tcl/Tk and X11, and interacts with the package database via the CLI of ''pacman''.|http://sourceforge.net/projects/tkpacman|{{AUR|tkpacman}}}}
  
==== Alias ====
+
=== Utilities ===
  
Add this [[alias]] to use pacman-color when available:
+
* {{App|Lostfiles|Script that identifies files not owned by any package.|https://github.com/graysky2/lostfiles|{{AUR|lostfiles}}}}
 +
* {{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|{{AUR|pacutils-git}}}}
 +
* {{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|srcpac|Simple tool that automates rebuilding packages from source.|https://projects.archlinux.org/srcpac.git|{{Pkg|srcpac}}}}
 +
* {{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|{{aur|snap-pac}}}}
  
For bash (and zsh):
+
== Maintenance ==
alias pacman='PACMAN=/usr/bin/pacman; [ -f /usr/bin/pacman-color ] && PACMAN=/usr/bin/pacman-color; $PACMAN $@'
+
  
For tcsh:
+
{{Expansion|{{ic|1=Usage=}} introduced with pacman 4.2, see [http://allanmcrae.com/2014/12/pacman-4-2-released/]}}
alias pacman 'set PACMAN=/usr/bin/pacman; [ -f /usr/bin/pacman-color ] && set PACMAN=/usr/bin/pacman-color; $PACMAN $argv'
+
  
=== 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.
+
See also [[System maintenance]].
  
==== Configure the shell ====
+
=== Listing packages ===
  
Add the following examples, which work in both [[Bash]] and [[Zsh]]:
+
You may want to get the list of installed packages with their version, which is useful when reporting bugs or discussing installed packages.
{{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
+
* List all explicitly installed packages: {{ic|pacman -Qe}}.
alias pacupd='sudo pacman -Sy && sudo abs'    # Update and refresh the local package and ABS databases against repositories
+
* List all explicitly installed native packages (i.e. present in the sync database) that are not direct or optional dependencies: {{ic|pacman -Qent}}.
alias pacinsd='sudo pacman -S --asdeps'        # Install given package(s) as dependencies of another package
+
* List all foreign packages (typically manually downloaded and installed): {{ic|pacman -Qm}}.
alias pacmir='sudo pacman -Syy'               # Force refresh of all package lists after updating /etc/pacman.d/mirrorlist
+
* List all native packages (installed from the sync database(s)): {{ic|pacman -Qn}}.
</nowiki>}}
+
* 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}}).
  
==== Usage ====
+
==== With size ====
  
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:
+
To get a list of installed packages sorted by size, which may be useful when freeing space on your hard drive:
$ pacupg
+
Install packages from repositories:
+
$ pacin <package1> <package2> <package3>
+
Install a custom built package:
+
$ pacins /path/to/<package>
+
Completely remove a locally installed package:
+
$ pacrem <package>
+
Search for available packages in the repositories:
+
$ pacreps <keywords>
+
Display information about a package (e.g. size, dependencies) in the repositories:
+
$ pacrep <keywords>
+
  
==== Notes ====
+
* Install {{Pkg|expac}} and run {{ic|<nowiki>expac -H M '%m\t%n' | sort -h</nowiki>}}.
 +
* Run {{Pkg|pacgraph}} with the {{ic|-c}} option.
  
The aliases used above are merely examples. By following the syntax samples above, rename the aliases as convenient. For example:
+
To list the download size of several packages (leave {{ic|''packages''}} blank to list all packages):
  
  alias pacrem='sudo pacman -Rns'
+
  $ expac -S -H M '%k\t%n' ''packages''
alias pacout='sudo pacman -Rns'
+
  
In the case above, the commands {{ic|pacrem}} and {{ic|pacout}} both call your shell to execute the same command.
+
To list explicitly installed packages not in {{Grp|base}} nor {{Grp|base-devel}} with size and description:
  
=== Operations and Bash syntax ===
+
$ expac -H M "%011m\t%-20n\t%10d" $(comm -23 <(pacman -Qqen | sort) <(pacman -Qqg base base-devel | sort)) | sort -n
  
In addition to pacman's standard set of features, there are ways to extend its usability through rudimentary [[Bash]] commands/syntax.
+
==== By date ====
  
* To install a number of packages sharing similar patterns in their names -- not the entire group nor all matching packages; eg. {{Pkg|kde}}:
+
To list the 20 last installed packages with {{Pkg|expac}}, run:
  
  # pacman -S kde-{applets,theme,tools}
+
  $ expac --timefmt='%Y-%m-%d %T' '%l\t%n' | sort | tail -20
  
* Of course, that is not limited and can be expanded to however many levels needed:
+
or, with seconds since the epoch (1970-01-01 UTC):
  
  # pacman -S kde-{ui-{kde,kdemod},kdeartwork}
+
  $ expac --timefmt=%s '%l\t%n' | sort -n | tail -20
  
* 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:
+
==== Not in a specified group or repository ====
  
# pacman -Ss '^vim-'
+
{{Note|To get a list of packages installed as dependencies but no longer required by any installed package, see [[#Removing unused packages (orphans)]].}}
  
* 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:
+
List explicitely installed packages not in the {{Grp|base}} or {{Grp|base-devel}} groups:
  
  # pacman -S $(pacman -Qq | grep compiz)
+
  $ comm -23 <(pacman -Qeq | sort) <(pacman -Qgq base base-devel | sort)
  
== Maintenance ==
+
List all installed packages unrequired by other packages, and which are not in the {{Grp|base}} or {{Grp|base-devel}} groups:
  
''House keeping, in the interest of keeping a clean system and following [[The Arch Way]]''
+
$ comm -23 <(pacman -Qqt | sort) <(pacman -Sqg base base-devel | sort)
  
=== Selectively clean cache ===
+
As above, but with descriptions:
  
* Use {{ic|paccache}} from {{pkg|pacman-contrib}} to clean the {{ic|/var/cache/pacman/pkg}} directory while allowing to specify how many package versions should be retained (default is 3):
+
$ expac -HM '%-20n\t%10d' $(comm -23 <(pacman -Qqt | sort) <(pacman -Qqg base base-devel | sort))
  
paccache -rv
+
List all installed packages that are ''not'' in the specified repository ''repo_name''
  
To list all the options:
+
$ comm -23 <(pacman -Qtq | sort) <(pacman -Slq ''repo_name'' | sort)
  
{{ic|paccache -h}}
+
List all installed packages that are in the ''repo_name'' repository:
  
=== Listing all installed packages with size ===
+
$ comm -12 <(pacman -Qtq | sort) <(pacman -Slq ''repo_name'' | sort)
  
* You may want to get the list of installed packages sorted by size, which may be useful when freeing space on your hard drive.
+
=== Listing files owned by a package with size ===
pacman -Qi | awk '/^Name/ {pkg=$3} /Size/ {print $4$5,pkg}' | sort -n
+
* Use {{ic|pacsysclean}} from {{Pkg|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 ===
+
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.
  
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:
+
$ pacman -Qlq ''package'' | grep -v '/$' | xargs du -h | sort -h
  
{{hc|pacman-disowned|<nowiki>
+
=== Identify files not owned by any package ===
#!/bin/sh
+
  
tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$
+
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. The general process for doing so is:
db=$tmp/db
+
fs=$tmp/fs
+
  
mkdir "$tmp"
+
# Create a sorted list of the files you want to check ownership of: {{bc|<nowiki>$ find /etc /opt /usr | sort > all_files.txt</nowiki>}}
trap 'rm -rf "$tmp"' EXIT
+
# Create a sorted list of the files tracked by pacman (and remove the trailing slashes from directories): {{bc|<nowiki>$ pacman -Qlq | sed 's|/$||' | sort > owned_files.txt</nowiki>}}
 +
# Find lines in the first list that are not in the second: {{bc|$ comm -23 all_files.txt owned_files.txt}}
  
pacman -Qlq | sort -u > "$db"
+
This process is tricky in practice because many important files are not part of any package (e.g. files generated at runtime, custom configs) and so will be included in the final output, making it difficult to pick out the files that can be safely deleted.
  
find /bin /etc /lib /sbin /usr \
+
{{Tip|The {{AUR|lostfiles}} script performs similar steps, but also includes an extensive blacklist to remove common false positives from the output.}}
  ! -name lost+found \
+
  \( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
+
  
comm -23 "$fs" "$db"</nowiki>}}
+
=== Removing unused packages (orphans) ===
  
To generate the list:
+
For ''recursively'' removing orphans and their configuration files:
  
  $ pacman-disowned > non-db.txt
+
  # pacman -Rns $(pacman -Qtdq)
  
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}}.
+
If no orphans were found, pacman errors with {{ic|error: no targets specified}}. This is expected as no arguments were passed to {{ic|pacman -Rns}}.
  
=== Removing orphaned packages ===
+
{{Note|As of {{Pkg|pacman}} 4.2.0, {{ic|-Qt}} lists only true orphans. To include packages which are ''optionally'' required by another package, pass the {{ic|-t}} flag twice (''i.e.'', {{ic|-Qtt}}).}}
  
For ''recursively'' removing orphans:
+
{{Merge|pacman#Installation reason|Should be described on the main page as a ''prevention''.}}
  
{{bc|# pacman -Rs $(pacman -Qtdq)}}
+
Note that the {{ic|-Rns}} (or {{ic|-Rnc}}) option will remove only direct dependencies but not optional dependencies that were explicitly installed (without {{ic|--asdeps}} option).
  
The following '''alias''' is easily inserted into {{ic|~/.bashrc}} and removes orphans if found:
+
Although it is not a requirement, but only for better system maintenance whenever you are installing optional dependencies try to install them with {{ic| --asdeps}} option. Doing this doesn't affect anything in runtime or installation. It only affects when you have removed a package and there were optional dependencies. Then if you remove orphans it will also remove leftover optional dependencies if they were installed using {{ic|--asdeps}} option. So while you are installing optional dependencies, use the following command:
  
{{hc|~/.bashrc|<nowiki># '[r]emove [o]rphans' - recursively remove ALL orphaned packages
+
# pacman -S --asdeps <packages that are optional dependencies>
alias pacro="/usr/bin/pacman -Qtdq &gt; /dev/null &amp;&amp; sudo /usr/bin/pacman -Rs \$(/usr/bin/pacman -Qtdq | sed -e ':a;N;$!ba;s/\n/ /g')"</nowiki>}}
+
 
+
The following '''function''' is easily inserted into {{ic|~/.bashrc}} and removes orphans if found:
+
 
+
{{hc|~/.bashrc|<nowiki>
+
orphans() {
+
  if [[ ! -n $(pacman -Qdt) ]]; then
+
    echo "No orphans to remove."
+
  else
+
    sudo pacman -Rs $(pacman -Qdtq)
+
  fi
+
}</nowiki>}}
+
  
 
=== Removing everything but base group ===
 
=== Removing everything but base group ===
Line 176: Line 145:
 
If it is ever necessary to remove all packages except the base group, try this one liner:
 
If it is ever necessary to remove all packages except the base group, try this one liner:
  
  # pacman -Rs $(comm -23 <(pacman -Qeq|sort) <((for i in $(pacman -Qqg base); do pactree -ul $i; done)|sort -u|cut -d ' ' -f 1))
+
  # pacman -R $(comm -23 <(pacman -Qq | sort) <((for i in $(pacman -Qqg base); do pactree -ul "$i"; done) | sort -u))
 
+
Source: [https://bbs.archlinux.org/viewtopic.php?id=130176 Look at discussion here]
+
 
+
Notes:
+
 
+
# {{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. For example:
+
 
+
{{hc|$ pactree -lu logrotate|
+
logrotate
+
popt
+
glibc
+
linux-api-headers
+
tzdata
+
dcron cron
+
bash
+
readline
+
ncurses
+
gzip}}
+
 
+
The {{ic|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 ===
+
  
pacman -Qq |grep -Fv -f <(pacman -Qqm)
+
The one-liner was originally devised in [https://bbs.archlinux.org/viewtopic.php?id=130176 this discussion], and later improved in this article.
  
 
=== Getting the dependencies list of several packages ===
 
=== Getting the dependencies list of several packages ===
  
 
Dependencies are alphabetically sorted and doubles are removed.
 
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 skipped
 
(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.
 
  
$ pacman -Si $@ 2>/dev/null | awk -F ": " -v filter="^Depends" \ '$0 ~ filter {gsub(/[>=<][^ ]*/,"",$2) ; gsub(/ +/,"\n",$2) ; print $2}' | sort -u
+
{{Note|To only show the tree of local installed packages, use {{ic|pacman -Qi}}.}}
  
Alternatively, you can use {{ic|expac}}: {{ic|expac -l '\n' %E -S $@ &#124; sort -u}}.
+
$ pacman -Si ''packages'' | awk -F'[:<=>]' '/^Depends/ {print $2}' | xargs -n1 | sort -u
  
=== Getting the size of several packages ===
+
Alternatively, with {{Pkg|expac}}:
  
You can use (and tweak) this little shell function:
+
$ expac -l '\n' %E -S ''packages'' | sort -u
  
{{hc|~/.bashrc|<nowiki>
+
=== Listing changed backup files ===
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
+
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:
not [[yaourt]] since AUR's PKGBUILD do not have size information.
+
  
A nice one-liner:
 
 
$ 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)}')
 
 
You should replace "$@" with packages, or put this line in a shell function.
 
 
=== Listing changed configuration files ===
 
If you want to backup your system configuration files you could copy all files in {{ic|/etc/}}, but usually you're only interested in the files that you have changed. In this case you want to list those changed configuration files, we can do this with the following command:
 
 
  # pacman -Qii | awk '/^MODIFIED/ {print $2}'
 
  # pacman -Qii | awk '/^MODIFIED/ {print $2}'
The following script does the same. You need to run it as root or with sudo.
 
{{hc|changed-files.sh|<nowiki>
 
#!/bin/bash
 
for package in /var/lib/pacman/local/*; do
 
sed '/^%BACKUP%$/,/^%/!d' $package/files | tail -n+2 | grep -v '^$' | while read file hash; do
 
[ "$(md5sum /$file | (read hash file; echo $hash))" != "$hash" ] && echo $(basename $package) /$file
 
done
 
done
 
</nowiki>}}
 
  
=== Listing all packages that nothing else depends on ===
+
Running this command with root permissions will ensure that files readable only by root (such as {{ic|/etc/sudoers}}) are included in the output.
If you want to generate a list of all installed packages that nothing else depends on, you can use the following script. This is very helpful if you are trying to free hard drive space and have installed a lot of packages that you may not remember. You can browse through the output to find packages which you no longer need.
+
  
{{hc|clean|<nowiki>
+
{{Tip|See [[#Listing all changed files from packages]] to list all changed files pacman knows, not only backup files.}}
#!/bin/bash
+
  
# This script is designed to help you clean your computer from unneeded
+
=== Back-up the pacman database ===
# packages. The script will find all packages that no other installed package
+
# depends on. It will output this list of packages excluding any you have
+
# placed in the ignore list. You may browse through the script's output and
+
# remove any packages you do not need.
+
  
# Enter groups and packages here which you know you wish to keep. They will
+
The following command can be used to back up the local pacman database:
# not be included in the list of unrequired packages later.
+
ignoregrp="base base-devel"
+
ignorepkg=""
+
  
# Temporary file locations
+
$ tar -cjf pacman_database.tar.bz2 /var/lib/pacman/local
tmpdir=/tmp
+
ignored=$tmpdir/ignored
+
installed=$tmpdir/installed
+
  
# Generate list of installed packages and packages you wish to keep.
+
Store the backup pacman database file on one or more offline media, such as a USB stick, external hard drive, or CD-R.
echo $(pacman -Sg $ignoregrp | awk '{print $2}') $ignorepkg | tr ' ' '\n' | sort | uniq > $ignored
+
pacman -Qq | sort > $installed
+
  
# Do not loop packages you are keeping
+
The database can be restored by moving the {{ic|pacman_database.tar.bz2}} file into the {{ic|/}} directory and executing the following command:
loop=$(comm -13 $ignored $installed)
+
  
# Check each remaining package. If package is not required by anything and
+
# tar -xjvf pacman_database.tar.bz2
# is not on your ignore list, print the package name to the screen.
+
for line in $loop; do
+
  check=$(pacman -Qi $line | awk '/Required By/ {print $4}')
+
  if [ "$check" == 'None' ]; then echo $line; fi
+
done
+
  
# Clean up $tmpdir
+
{{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 [[Pacman tips#Restore pacman's local database]].}}
rm $ignored $installed
+
</nowiki>}}
+
  
If you install {{pkg|expac}} you can run {{ic|<nowiki>expac "%n %N" -Q $(expac "%n %G" | grep -v ' base') | awk '$2 == "" {print $1}'</nowiki>}} which should give the same results but much faster.
+
{{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}}.}}
  
=== Backing up Local database with Systemd ===
+
=== Check changelogs easily ===
  
[https://wiki.archlinux.org/index.php/Systemd Systemd] can take snapshots of the pacman local database everytime it is modified.
+
When maintainers update packages, commits are often commented in a useful fashion. Users can quickly check these from the command line by installing {{AUR|paclog}}. This utility lists recent commit messages for packages from the official repositories or the AUR, by using {{ic|paclog package}}.
 
+
{{Tip| Save the following script as {{ic|/usr/lib/systemd/scripts/pakbak_script}}.}}
+
{{Note| Change the value of {{ic|$pakbak}} to modify where the backed up database is stored.}}
+
{{bc|<nowiki>
+
#!/bin/bash
+
 
+
declare -r pakbak="/pakbak.bz2";  ## set backup location
+
tar -cjf "$pakbak" "/var/lib/pacman/local";  ## compress & store pacman local database in $pakbak
+
</nowiki>}}
+
 
+
{{Tip|Save the following [https://wiki.archlinux.org/index.php/Systemd#Writing_custom_.service_files service file] as {{ic|/usr/lib/systemd/system/pakbak.service}}.}}
+
{{bc|<nowiki>
+
[Unit]
+
Description=Back up pacman database
+
 
+
[Service]
+
Type=oneshot
+
ExecStart=/bin/bash /usr/lib/systemd/scripts/pakbak_script
+
RemainAfterExit=no
+
</nowiki>}}
+
 
+
{{Tip|Save the following [https://wiki.archlinux.org/index.php/Systemd#Writing_custom_.service_files path] file as {{ic|/usr/lib/systemd/system/pakbak.path}}.}}
+
{{bc|<nowiki>
+
[Unit]
+
Description=Back up pacman database
+
 
+
[Path]
+
PathChanged=/var/lib/pacman/local
+
Unit=pakbak.service
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
{{Tip|To start the backup service :
+
{{bc|<nowiki>
+
# systemctl start pakbak.path
+
</nowiki>}}
+
To enable the backup service automatically on reboot :
+
{{bc|<nowiki>
+
# systemctl enable pakbak.path
+
</nowiki>}}
+
}}
+
  
 
== Installation and recovery ==
 
== Installation and recovery ==
  
''Alternative ways of getting and restoring packages.''
+
Alternative ways of getting and restoring packages.
  
 
=== Installing packages from a CD/DVD or USB stick ===
 
=== 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 369: Line 215:
 
  # 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 that 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|2=
+
{{hc|/etc/pacman.conf|2=
 
[custom]
 
[custom]
 
SigLevel = PackageRequired
 
SigLevel = PackageRequired
Line 378: Line 224:
 
'''3.''' Finally, synchronize the pacman database to be able to use the new repository:
 
'''3.''' Finally, synchronize the pacman database to be able to use the new repository:
  
  # pacman -Sy
+
  # pacman -Syu
  
 
=== Custom local repository ===
 
=== Custom local repository ===
  
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.
+
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. 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):
 
+
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):
+
  
 
  $ repo-add /path/to/repo.db.tar.gz /path/to/*.pkg.tar.xz
 
  $ 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.
+
{{Note|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.
 +
Furthermore when using {{ic|repo-add}} keep in mind that 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.}}
  
To add a new package (and remove the old if it exists), run:
+
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/packagetoadd-1.0-1-i686.pkg.tar.xz
 
  $ 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'' is used in the exact same manner as ''repo-add'', except that the packages listed on the command line are removed from the repository database.
  
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 {{ic|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.
Line 402: Line 247:
 
=== Network shared pacman cache ===
 
=== Network shared pacman cache ===
  
{{Tip|See [http://xyne.archlinux.ca/projects/pacserve/ pacserve] for an alternative (and probably simpler) solution.}}
+
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 and dirty solution, you can simply run a standalone webserver which other computers can use as a first mirror: {{ic|darkhttpd /var/cache/pacman/pkg}}. Just add this server at the top of your mirror list. Be aware that you might get a lot of 404 errors, due to cache misses, depending on what you do, but pacman will try the next (real) mirrors when that happens.
 +
 
 +
==== Read-write cache ====
 +
 
 +
{{Tip|See [[pacserve]] for an alternative (and probably simpler) solution than what follows.}}
  
 
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.
 
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.
  
First, install any network-supporting filesystem; for example [[sshfs]], [[shfs]], [[ftpfs]], [[smbfs]] or [[nfs]].
+
First, install any network-supporting filesystem; for example [[sshfs]], [[shfs]], ftpfs, [[smbfs]] or [[nfs]].
  
{{Tip|To use sshfs or shfs, consider reading [[Using SSH Keys]].}}
+
{{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|/var/lib/pacman/sync/{core,extra,testing,community} }} in the same way. Proceed to place the appropriate lines in {{ic|/etc/fstab}}.
+
==== Dynamic reverse proxy cache using nginx ====
  
==== Preventing unwanted cache purges ====
+
[[nginx]] can be used to proxy requests to official upstream mirrors and cache the results to local disk. All subsequent requests for that file will be served directly from the local cache, minimizing the amount of internet traffic needed to update a large number of servers with minimal effort.
  
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.
+
{{Warning| This method has a limitation. You must use mirrors that use the same relative path to package files and you must configure your cache to use that same path. In this example, we are using mirrors that use the relative path {{ic|/archlinux/$repo/os/$arch}} and our cache's {{ic|Server}} setting in {{ic|mirrorlist}} is configured similarly.}}
  
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}}:
+
In this example, we will run the cache server on {{ic|<nowiki>http://cache.domain.local:8080/</nowiki>}} and storing the packages in {{ic|/srv/http/pacman-cache/}}.
  
CleanMethod = KeepCurrent
+
Create the directory for the cache and adjust the permissions so nginx can write files to it:
  
=== Backing up and retrieving a list of installed packages ===
+
  # mkdir /srv/http/pacman-cache
 +
  # chown http:http /srv/http/pacman-cache
  
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.
+
Next, configure nginx as the [https://gist.github.com/anonymous/97ec4148f643de925e433bed3dc7ee7d dynamic cache] (read the comments for an explanation of the commands).
  
* First, backup the current list of non-local packages:
+
Finally, update your other Arch Linux servers to use this new cache by adding the following line to the {{ic|mirrorlist}} file:
  
: $ comm -23 <(pacman -Qeq|sort) <(pacman -Qmq|sort) > pkglist.txt
+
{{hc|/etc/pacman.d/mirrorlist|<nowiki>
 +
Server = http://cache.domain.local:8080/archlinux/$repo/os/$arch
 +
...
 +
</nowiki>}}
  
* Store the {{ic|pkglist.txt}} on a USB key or other convenient medium or gist.github.com or Evernote, Dropbox, etc.
+
{{Note| You will need to create a method to clear old packages, as this directory will continue to grow over time. {{ic|paccache}} (which is included with {{ic|pacman}}) 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.}}
  
* Copy the {{ic|pkglist.txt}} file to the new installation, and navigate to the directory containing it.
+
==== Synchronize pacman package cache using BitTorrent Sync ====
  
* Issue the following command to install from the backup list:
+
[[BitTorrent Sync]] is a new way of synchronizing folder via network (it works in LAN and over the internet). It is peer-to-peer so you do not need to set up a server: follow the link for more information.
 +
How to share a pacman cache using BitTorrent Sync:
 +
* First install the {{AUR|btsync}} package from the AUR on the machines you want to sync
 +
* Follow the installation instructions of the AUR package or on the [[BitTorrent Sync]] wiki page
 +
** set up BitTorrent Sync to work for the root account. This process requires read/write to the pacman package cache.
 +
** make sure to set a good password on btsync's web UI 
 +
** start the systemd daemon for btsync.
 +
** in the btsync Web GUI add a new synchronized folder on the first machine and generate a new Secret. Point the folder to {{ic|/var/cache/pacman/pkg}}
 +
** Add the folder on all the other machines using the same Secret to share the cached packages between all systems. Or, to set the first system as a master and the others as slaves, use the Read Only Secret. Be sure to point it to {{ic|/var/cache/pacman/pkg}}
  
: # pacman -S $(< pkglist.txt)
+
Now the machines should connect and start synchronizing their cache. Pacman works as expected even during synchronization. The process of syncing is entirely automatic.
  
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).
+
==== Preventing unwanted cache purges ====
  
In such a case, you may still want to install all available packages from that list:
+
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.
  
# pacman -S --needed $(comm -12 <(pacman -Slq|sort) <(sort badpkdlist) )
+
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}}:
  
Explanation:
+
CleanMethod = KeepCurrent
  
* {{ic|pacman -Slq}} lists all available softwares, but the list is sorted by repository first, hence the {{ic|sort}} command.
+
=== Recreate a package from the file system ===
* 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):
+
To recreate a package from the file system, use ''bacman'' (included with pacman). 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 Rollback Machine]] for alternatives.
  
$ yaourt -S --needed $(comm -13 <(pacman -Slq|sort) <(sort badpkdlist) )
+
{{Tip|''bacman'' honours the {{ic|PACKAGER}}, {{ic|PKGDEST}} and {{ic|PKGEXT}} options from {{ic|makepkg.conf}}. Custom options for the compression tools can be configured by exporting the relevant environment variable, for example {{ic|1=XZ_OPT="-T 0"}} will enable parallel compression for ''xz''.}}
  
Finally, you may want to remove all the packages on your system that are not mentioned in the list.
+
An alternative tool would be {{AUR|fakepkg}}. It supports parallelization and can handle multiple input packages in one command, which ''bacman'' both does not support.
  
{{Warning|Use this command wisely, and always check the result prompted by pacman.}}
+
=== List of installed packages ===
  
# pacman -Rsu $(comm -23 <(pacman -Qq|sort) <(sort pkglist))
+
{{Expansion|Optional dependencies that are not required by any other package ({{ic|comm -13 <(pacman -Qdtq) <(pacman -Qdttq)}}) are ignored by this procedure.}}
  
=== List downloaded packages that are not in base or base-devel ===
+
{{Tip|1=<nowiki></nowiki>
 +
* These tasks can be automated, see {{AUR|plist-gist}} or [https://bbs.archlinux.org/viewtopic.php?id=200067 bacpac] for examples.
 +
* To skip already installed packages, use {{ic|--needed}}.}}
  
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:
+
Keeping a list of native, explicitly installed packages can be useful to speed up installation on a new system.
  
  $ comm -23 <(pacman -Qeq|sort) <(pacman -Qgq base base-devel|sort)
+
  $ pacman -Qqen > pkglist.txt
  
=== Reinstalling all installed packages ===
+
To install packages from the list backup, run:
  
If you mess up your system ({{ic|rm -rf}}) you can repair by having pacman reinstall all of your packages.  
+
# pacman -S - < pkglist.txt
  
If your system does not contain any foreign (AUR) packages you can run:
+
In case the list includes foreign packages, such as [[AUR]] packages, remove them first:
  
  # pacman -Qeq | pacman -S -
+
  # pacman -S $(comm -12 <(pacman -Slq | sort) <(sort pkglist))
  
Pacman preserves the installation reason by default.
+
To remove all the packages on your system that are not mentioned in the list.
  
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.
+
# pacman -Rsu $(comm -23 <(pacman -Qq | sort) <(sort pkglist))
  
The following will reinstall every package found in the repositories:
+
=== Listing all changed files from packages ===
  
# comm -23 <(pacman -Qeq|sort) <(pacman -Qmq|sort) | pacman -S -
+
If you are suspecting file corruption (e.g. by software/hardware failure), but are unsure if files were got corrupted, you might want to compare with the hash sums in the packages. This can be done with {{AUR|pacutils}}:
  
=== Restore pacman's local database ===
+
# paccheck --md5sum --quiet
  
Signs that pacman needs a local database restoration:
+
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]].
  
* {{ic|pacman -Q}} gives absolutely no output, and {{Ic|pacman -Syu}} erroneously reports that the system is up to date.
+
{{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.}}
* When trying to install a package using {{ic|pacman -S package}}, and it outputs a list of already satisfied dependencies.
+
* When {{ic|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.
+
=== Reinstalling all packages ===
 +
To reinstall all native packages, use:
  
Firstly, make sure pacman's log file is present:
+
# pacman -Qnq | pacman -S -
  
$ ls /var/log/pacman.log
+
Foreign (AUR) packages must be reinstalled separately; you can list them with {{ic|pacman -Qmq}}.
  
If it does not exist, it is ''not'' possible to continue with this method. You may be able to use [https://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.
+
Pacman preserves the [[installation reason]] by default.
  
==== Log filter script ====
+
=== Restore pacman's local database ===
  
You need to install '''paclog-pkglist''' from {{Pkg|pacman-contrib}} and create following script:
+
See [[Pacman/Restore_local_database]].
  
{{hc|pacrecover|<nowiki>
+
=== Recovering a USB key from existing install ===
#!/bin/bash -e
+
  
. /etc/makepkg.conf
+
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)
  
PKGCACHE=$((grep -m 1 '^CacheDir' /etc/pacman.conf || echo 'CacheDir = /var/cache/pacman/pkg') | sed 's/CacheDi$
+
# pacman -S $(pacman -Qq --dbpath /newarch/var/lib/pacman) --root /newarch --dbpath /newarch/var/lib/pacman
  
pkgdirs=("$@" "$PKGDEST" "$PKGCACHE")
+
=== Viewing a single file inside a .pkg file ===
  
while read -r -a parampart; do
+
For example, if you want to see the contents of {{ic|/etc/systemd/logind.conf}} supplied within the {{Pkg|systemd}} package:
  pkgname="${parampart[0]}-${parampart[1]}-*.pkg.tar.xz"
+
  for pkgdir in ${pkgdirs[@]}; do
+
    pkgpath="$pkgdir"/$pkgname
+
    [ -f $pkgpath ] && { echo $pkgpath; break; };
+
  done || echo ${parampart[0]} 1>&2
+
done
+
</nowiki>}}
+
+
Make the script executable:
+
  
  $ chmod +x pacrecover
+
  $ tar -xOf /var/cache/pacman/pkg/systemd-204-3-x86_64.pkg.tar.xz etc/systemd/logind.conf
  
==== Generating the package recovery list ====
+
Or you can use {{pkg|vim}} to browse the archive:
  
{{Warning|If for some reason your [[pacman]] cache or [[makepkg]] package destination contain packages for other architectures, remove them before continuation.}}
+
$ vim /var/cache/pacman/pkg/systemd-204-3-x86_64.pkg.tar.xz
  
Run the script (optionally passing additional directories with packages as parameters):
+
=== Find applications that use libraries from older packages ===
  
$ paclog-pkglist /var/log/pacman.log | ./pacrecover >files.list 2>pkglist.orig
+
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.
  
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.
+
Here is a way how to find all the programs that use old packages code:
  
Here is a way to automatically restrict second list to packages available in a repository:
+
# 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.
  
$ { cat pkglist.orig; pacman -Slq; } | sort | uniq -d > pkglist
+
== Performance ==
  
Check if some important ''base'' package are missing, and add them to the list:
+
=== Database access speeds ===
  
  $ comm -23 <(pacman -Sgq base) pkglist.orig >> pkglist
+
Pacman stores all package information in a collection of small files, one for each package. Improving database access speeds reduces the time taken in database-related tasks, e.g. searching packages and resolving package dependencies.  The safest and easiest method is to run as root:
  
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/}}.
+
# pacman-optimize
  
==== Performing the recovery ====
+
This will attempt to put all the small files together in one (physical) location on the hard disk so that the hard disk head does not have to move so much when accessing all the data.  This method is safe, but is not foolproof: it depends on your filesystem, disk usage and empty space fragmentation.  Another, more aggressive, option would be to first remove uninstalled packages from cache and to remove unused repositories before database optimization:
  
Define bash alias for recovery purposes:
+
# pacman -Sc && pacman-optimize
  
# recovery-pacman() {
+
=== Download speeds ===
    pacman "$@"      \
+
    --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.
+
{{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].}}
  
Populate the sync database:
+
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 -Sy
+
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.
  
Start database generation by installing locally available package files from {{ic|files.list}}:
+
In all cases, make sure you have the latest Pacman before doing any modifications.
  
  # recovery-pacman -U $(< files.list)
+
  # pacman -Syu
  
Install the rest from {{ic|pkglist}}:
+
==== Powerpill ====
  
# recovery-pacman -S $(< pkglist)
+
See [[Powerpill]].
  
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.
+
==== wget ====
  
# pacman -D --asdeps $(pacman -Qq)
+
This is also very handy if you need more powerful proxy settings than pacman's built-in capabilities.
# pacman -D --asexplicit $(pacman -Qtq)
+
  
Optionally check all installed packages for corruption:
+
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:
  
  # pacman -Qk
+
  XferCommand = /usr/bin/wget -c -q --show-progress --passive-ftp -O %o %u
  
Optionally [[#Identify files not owned by any package]].
+
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}}.
  
Update all packages:
+
==== aria2 ====
  
# pacman -Su
+
[[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.
  
=== Recovering a USB key from existing install ===
+
{{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]].}}
  
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)
+
Install {{Pkg|aria2}}, then edit {{ic|/etc/pacman.conf}} by adding the following line to the {{ic|[options]}} section:
  
  # pacman -S $(pacman -Qq --dbpath /newarch/var/lib/pacman) --root /newarch --dbpath /newarch/var/lib/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
  
=== Extracting contents of a .pkg file ===
+
{{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.}}
  
The {{ic|.pkg}} files ending in {{ic|.xz}} are simply tar'ed archives that can be decompressed with:
+
See [http://aria2.sourceforge.net/manual/en/html/aria2c.html#options OPTIONS] in {{ic|man aria2c}} for used aria2c options.
  
$ tar xvf package.tar.xz
+
* {{ic|-d, --dir}} :The directory to store the downloaded file(s) as specified by [[pacman]].
 +
* {{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.
  
If you want to extract a couple of files out of a {{ic|.pkg}} file, this would be a way to do it.
+
==== Other applications ====
 
+
=== Viewing a single file inside a .pkg file ===
+
  
For example, if you want to see the contents of {{ic|/etc/conf.d/ntpd.conf}} supplied within the {{Pkg|ntp}} package:
+
There are other downloading applications that you can use with Pacman. Here they are, and their associated XferCommand settings:
  
$ tar -xOf /var/cache/pacman/pkg/ntp-4.2.6.p5-6-i686.pkg.tar.xz etc/conf.d/ntpd.conf
+
* {{ic|snarf}}: {{ic|1=XferCommand = /usr/bin/snarf -N %u}}
Or you can use vim, then browse the archive:
+
* {{ic|lftp}}: {{ic|1=XferCommand = /usr/bin/lftp -c pget %u}}
$ vim /var/cache/pacman/pkg/ntp-4.2.6.p5-6-i686.pkg.tar.xz
+
* {{ic|axel}}: {{ic|1=XferCommand = /usr/bin/axel -n 2 -v -a -o %o %u}}

Latest revision as of 10:39, 28 May 2016

Related articles

See pacman for the main article.

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

Cosmetic and convenience

Graphical front-ends

  • Discover — A collection of package management tools for KDE, using PackageKit.
https://projects.kde.org/projects/kde/workspace/discover || discover
  • GNOME packagekit — GTK based package management tool
http://www.freedesktop.org/software/PackageKit/ || gnome-packagekit
  • GNOME Software — Gnome Software App. (Curated selection for GNOME)
https://wiki.gnome.org/Apps/Software || gnome-software
  • pcurses — Package management in a curses frontend
https://github.com/schuay/pcurses || pcurses
  • tkPacman — Depends only on Tcl/Tk and X11, and interacts with the package database via the CLI of pacman.
http://sourceforge.net/projects/tkpacman || tkpacmanAUR

Utilities

  • Lostfiles — Script that identifies files not owned by any package.
https://github.com/graysky2/lostfiles || lostfilesAUR
  • Pacmatic — Pacman 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-gitAUR
  • 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
  • srcpac — Simple tool that automates rebuilding packages from source.
https://projects.archlinux.org/srcpac.git || srcpac
  • snap-pac — Make pacman automatically use snapper to create pre/post snapshots like openSUSE's YaST.
https://github.com/wesbarnett/snap-pac || snap-pacAUR

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

To get a list of installed packages sorted by size, which may be useful when freeing space on your hard drive:

  • 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 base nor base-devel with size and description:

$ expac -H M "%011m\t%-20n\t%10d" $(comm -23 <(pacman -Qqen | sort) <(pacman -Qqg base base-devel | sort)) | sort -n

By date

To list the 20 last installed packages with expac, run:

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

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

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

Not in a specified group or repository

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

List explicitely installed packages not in the base or base-devel groups:

$ comm -23 <(pacman -Qeq | sort) <(pacman -Qgq base base-devel | sort)

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

$ comm -23 <(pacman -Qqt | sort) <(pacman -Sqg base base-devel | sort)

As above, but with descriptions:

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

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

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

List all installed packages that are in the repo_name repository:

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

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. The general process for doing so is:

  1. Create a sorted list of the files you want to check ownership of:
    $ find /etc /opt /usr | sort > all_files.txt
  2. Create a sorted list of the files tracked by pacman (and remove the trailing slashes from directories):
    $ pacman -Qlq | sed 's|/$||' | sort > owned_files.txt
  3. Find lines in the first list that are not in the second:
    $ comm -23 all_files.txt owned_files.txt

This process is tricky in practice because many important files are not part of any package (e.g. files generated at runtime, custom configs) and so will be included in the final output, making it difficult to pick out the files that can be safely deleted.

Tip: The lostfilesAUR script performs similar steps, but also includes an extensive blacklist to remove common false positives from the output.

Removing unused packages (orphans)

For recursively removing orphans and their configuration files:

# pacman -Rns $(pacman -Qtdq)

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

Note: As of pacman 4.2.0, -Qt lists only true orphans. To include packages which are optionally required by another package, pass the -t flag twice (i.e., -Qtt).

Merge-arrows-2.pngThis article or section is a candidate for merging with pacman#Installation reason.Merge-arrows-2.png

Notes: Should be described on the main page as a prevention. (Discuss in Talk:Pacman/Tips and tricks#)

Note that the -Rns (or -Rnc) option will remove only direct dependencies but not optional dependencies that were explicitly installed (without --asdeps option).

Although it is not a requirement, but only for better system maintenance whenever you are installing optional dependencies try to install them with --asdeps option. Doing this doesn't affect anything in runtime or installation. It only affects when you have removed a package and there were optional dependencies. Then if you remove orphans it will also remove leftover optional dependencies if they were installed using --asdeps option. So while you are installing optional dependencies, use the following command:

# pacman -S --asdeps <packages that are optional dependencies>

Removing everything but base group

If it is ever necessary to remove all packages except the base group, try this one liner:

# pacman -R $(comm -23 <(pacman -Qq | sort) <((for i in $(pacman -Qqg base); do pactree -ul "$i"; done) | sort -u))

The one-liner was originally devised in this discussion, and later improved in this article.

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.
$ 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, not only backup files.

Back-up the pacman database

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

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

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

The database can be restored by moving the 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 Pacman tips#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 paclogAUR. This utility lists recent commit messages for packages from the official repositories or the AUR, by using paclog 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. 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):

$ repo-add /path/to/repo.db.tar.gz /path/to/*.pkg.tar.xz
Note: 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. Furthermore when using repo-add keep in mind that 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.

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/packagetoadd-1.0-1-i686.pkg.tar.xz

repo-remove is used in the exact same manner as repo-add, except that the packages listed on the command line are removed from the repository database.

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

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 and dirty solution, you can simply run a standalone webserver which other computers can use as a first mirror: darkhttpd /var/cache/pacman/pkg. Just add this server at the top of your mirror list. Be aware that you might get a lot of 404 errors, due to cache misses, depending on what you do, but pacman will try the next (real) mirrors when that happens.

Read-write cache

Tip: See pacserve for an alternative (and probably simpler) solution than what follows.

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; for example sshfs, shfs, ftpfs, smbfs or nfs.

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.

Dynamic reverse proxy cache using nginx

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

Warning: This method has a limitation. You must use mirrors that use the same relative path to package files and you must configure your cache to use that same path. In this example, we are using mirrors that use the relative path /archlinux/$repo/os/$arch and our cache's Server setting in mirrorlist is configured similarly.

In this example, we will run the cache server on http://cache.domain.local:8080/ and storing the packages in /srv/http/pacman-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

Next, configure nginx as the dynamic cache (read the comments for an explanation of the commands).

Finally, update your other Arch Linux servers to use this new cache by adding the following line to the mirrorlist file:

/etc/pacman.d/mirrorlist
Server = http://cache.domain.local:8080/archlinux/$repo/os/$arch
...
Note: You will need to create a method to clear old packages, as this directory will continue to grow over time. paccache (which is included with pacman) 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 BitTorrent Sync

BitTorrent Sync is a new way of synchronizing folder via network (it works in LAN and over the internet). It is peer-to-peer so you do not need to set up a server: follow the link for more information. How to share a pacman cache using BitTorrent Sync:

  • First install the btsyncAUR package from the AUR on the machines you want to sync
  • Follow the installation instructions of the AUR package or on the BitTorrent Sync wiki page
    • set up BitTorrent Sync to work for the root account. This process requires read/write to the pacman package cache.
    • make sure to set a good password on btsync's web UI
    • start the systemd daemon for btsync.
    • in the btsync Web GUI add a new synchronized folder on the first machine and generate a new Secret. Point the folder to /var/cache/pacman/pkg
    • Add the folder on all the other machines using the same Secret to share the cached packages between all systems. Or, to set the first system as a master and the others as slaves, use the Read Only Secret. Be sure to point it to /var/cache/pacman/pkg

Now the machines should connect and start synchronizing their cache. Pacman works as expected even during synchronization. The process of syncing is entirely automatic.

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 bacman (included with pacman). 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 Rollback Machine for alternatives.

Tip: bacman honours the PACKAGER, PKGDEST and PKGEXT options from makepkg.conf. Custom options for the compression tools can be configured by exporting the relevant environment variable, for example XZ_OPT="-T 0" will enable parallel compression for xz.

An alternative tool would be fakepkgAUR. It supports parallelization and can handle multiple input packages in one command, which bacman both does not support.

List of installed packages

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

Reason: Optional dependencies that are not required by any other package (comm -13 <(pacman -Qdtq) <(pacman -Qdttq)) are ignored by this procedure. (Discuss in Talk:Pacman/Tips and tricks#)
Tip:
  • These tasks can be automated, see plist-gistAUR or bacpac for examples.
  • To skip already installed packages, use --needed.

Keeping a list of native, explicitly installed packages can be useful to speed up installation on a new system.

$ pacman -Qqen > pkglist.txt

To install packages from the list backup, run:

# pacman -S - < pkglist.txt

In case the list includes foreign packages, such as AUR packages, remove them first:

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

To remove all the packages on your system that are not mentioned in the list.

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

Listing all changed files from packages

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

# 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 -Qnq | pacman -S -

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

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:

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

Performance

Database access speeds

Pacman stores all package information in a collection of small files, one for each package. Improving database access speeds reduces the time taken in database-related tasks, e.g. searching packages and resolving package dependencies. The safest and easiest method is to run as root:

# pacman-optimize

This will attempt to put all the small files together in one (physical) location on the hard disk so that the hard disk head does not have to move so much when accessing all the data. This method is safe, but is not foolproof: it depends on your filesystem, disk usage and empty space fragmentation. Another, more aggressive, option would be to first remove uninstalled packages from cache and to remove unused repositories before database optimization:

# pacman -Sc && pacman-optimize

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

See Powerpill.

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 -c -q --show-progress --passive-ftp -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 man aria2c 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