Topic Contributors
creator avatar  
mreschke
Matthew Reschke
Site Developer
Created: Feb 23rd, 2009
Updated: Feb 20th, 2012
File
Download Selected (zip)
Download Selected (tar.gz)
Edit
Select All
Select None
View
Detail
Detail Preview
Icons
Preview
Show Hidden
Hide Hidden
Full Manager
Reset Defaults
Open In New Tab
Open In New Window
List Archive Contents
Download File
Open
Download Folder (as .zip)
ArchLinux Pacman Package Manager
Post # 137 permalink Topic #137 by mreschke on 2009-02-23 14:07:26 (viewed 2,035 times)

Pacman is the package manager application used by ArchLinux.

Pacmans config file is located at /etc/pacman.conf. Pacman uses different repositories of files. These repos can be added to your system through the pacman.conf. By default, pacman uses 3 repos; core, extra and community. There are a lot of mirrors for pacman across the globe, pacman uses the /etc/pacman.d/mirrorlist file to determine which mirrors to use. The speed of pacman greatly depends on which mirrors you choose. Pacman uses wget by default, but you can specify alternate downloaders (like aria2 for simultaneous mirror downloads) in the pacman.conf under the XferCommand = option. Pacman keeps a local database of available and installed package descriptions. Each day you should sync your local database using the pacman -Sy command, this is like debians apt-get update or aptitude update. Now your local database will be updated and any package you install with pacman -S xxxx will be up-to-date (as long as your mirrors have the latest package).

It seems that pacman syncs its local database with the first mirror in your mirrorlist file. I have had my entire system several updates behind because the first mirror in the list did not contain the latest packages, so even a pacman -Su (system upgrade) was behind. Therefore, I usually keep the actual ftp://archlinux.org mirror first in my mirrorlist to ensure that pacman -Sy gets the latest packages. Or if you use the http://www.archlinux.org/mirrors/status/ like my script below, you can tell it to only give you mirrors that are 100% up-to-date.

A Few Common Commands[-][- -][++]

If you use yaourt instead of pacman, the yaourt commands are exactly the same.

  1. Sync your local database to get an updated package list (do daily before an install/upgrade of packages) pacman -Sy, like apt-get update in debian
  2. Upgrade all your packages to the latest versions pacman -Su or pacman -Syu to sync then upgrade, like apt-get upgrade in debian
    1. If you use yaourt, perform a full upgrade with yaourt -Su and then upgrade any installed AUR applications with yaourt -Su --aur
  3. Search for a package to install pacman -Ss xxxx, like apt-cache search xxx in debian
  4. Search for an installed package pacman -Qs xxxx or pacman -Q to show all installed
  5. Info on a package pacman -Si xxxx
  6. Install a package pacman -S xxx or multiples with pacman -S xxxx yyyy zzzz, like apt-get install xxx in debian
    1. If you have yaourt installed, you can also simply download the source PKGBUILD with yaourt -G xxxx then run makepkg -s or of course just use abs
  7. Show orphaned packages pacman -Qqdt
    1. With yaourt you can delete them with yaourt -Qdt though this uses -Rcs which can be dangerous, better to use Rns bash below
    2. Or delete them with pacman using pacman -Rns $(pacman -Qqdt)
  8. Clean cache directory of uninstalled packages pacman -Sc
  9. Find which package a file belong in pacman -Qo /usr/bin/genisoimage
  10. Show packages that you explicitly installed (not installed as dependencies), great for backup list of what you installed pacman -Qqe
  11. Show which packages are in a repo pacman -Sl archlinuxfr
  12. Yaourt has a great clean utility to help merge/delete all the .pacnew config files, just use yaourt -C
  13. Reinstall every package you explicitly installed for pkg in $(pacman -Qqe); do sudo pacman -S --noconfirm --force $pkg; done

Customizations and Scripts[-][- -][++]

Updated and Ranked Mirrorlists[-][- -][++]

Mirrors can slow down or become outdated. I create a /usr/local/bin/update-mirrorlist script which gets the 10 fastest and 100% up-to-date mirrors from http://www.archlinux.org/mirrorlist/ I run it every week or so.

BASH Code Snippet
#!/usr/bin/env bash
 
#This script gets the most updated mirrorlists from archlinux.org
#Then runs rankmirrors, taking the 10 fastest mirrors
#mReschke 2011-03-23
 
#Backup oroginal mirrorlist
cp /etc/pacman.d/{mirrorlist,mirrorlist.before-update}
 
#Get the most up-to-date mirrorlists from archlinux.org (USA)
#Go here to do it manually: www.archlinux.org/mirrorlist/
curl "http://www.archlinux.org/mirrorlist/?country=United+States&protocol=ftp&protocol=http&ip_version=4&use_mirror_status=on" > /tmp/mirrorlist
 
#Remove main mirrorlist
#sed -i s/"#Server = ftp:\/\/ftp.archlinux.org\/\$repo\/os\/\$arch"//g /tmp/mirrorlist
 
#Remove comments from list
sed -i s/#Server/Server/g /tmp/mirrorlist
 
#Rankmirror (get top 10 fastest mirrors)
#Actually I think its already ranked by archlinux.org when generated
rankmirrors -n 10 /tmp/mirrorlist > /tmp/mirrorlist.ranked
 
#Write new mirrorlist
#echo 'Server = ftp://ftp.archlinux.org/$repo/os/$arch' > /etc/pacman.d/mirrorlist
cat /tmp/mirrorlist.ranked | grep -v Score > /etc/pacman.d/mirrorlist
 
#Cleanup
rm /tmp/{mirrorlist,mirrorlist.ranked}
 

Other Customizations[-][- -][++]

I prefer to have the [archlinuxfr] repo setup in my pacman.conf

/etc/pacman.conf
[archlinuxfr]
Server = http://repo.archlinux.fr/$arch

This repository has several extra packages. I mostly use it for the yaourt package. Yaourt is similar to pacman, but adds the ability to search and install packages from the AUR.

If pacman or yaourt needs an upgrade, it must be done first, before any other package can be installed, so in pacman.conf I add

/etc/pacman.conf
SyncFirst   = pacman pacman-color yaourt package-query

Sometimes I choose aria2 for downloading. This does NOT download from multiple mirrors at the same time, though there is a script that can at https://wiki.archlinux.org/index.php/Improve_Pacman_Performance

/etc/pacman.conf
XferCommand = /usr/bin/aria2c --allow-overwrite=true -c --file-allocation=none --log-level=error -m2 --max-connection-per-server=2 --max-file-not-found=5 --min-split-size=5M --no-conf --remote-time=true --summary-interval=60 -t5 -d / -o %o %u