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 pacman -Qeq | pacman -S -
  14. Ignore dependencies while installing pacman -Sd xxxx

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.

/usr/local/bin/update-mirrorlist
#!/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

Pacman Cache[-][--][++]

Use nginx like so

2023-11-24 12:51:30 toor@linstore in /etc/nginx/sites-enabled
ooo $ cat pacman-cache.conf 
# Pacman Cache
# mReschke 2020-04-23
server {
        listen 80;
        server_name pacman-cache.mreschke.net;
        root /store/data/cache/pacman;
        autoindex on;

        # Requests for package db, signature files and files db should redirect upstream without caching
        location ~ \.(db|sig|files)$ {
                proxy_pass http://pacman_mirrors$request_uri;
        }

        # Requests for actual packages should be served directly from cache if available.
        #   If not available, retrieve and save the package from an upstream mirror.
        location ~ \.tar\.(xz|zst)$ {
                try_files $uri @pkg_mirror;
        }

        # Retrieve package from upstream mirrors and cache for future requests
        location @pkg_mirror {
                proxy_store on;
                proxy_redirect off;
                proxy_store_access user:rw group:rw all:r;
                proxy_next_upstream error timeout http_404;
                proxy_pass http://pacman_mirrors$request_uri;
        }
}

# Upstream Arch Linux Mirrors
# - Configure as many backend mirrors as you want in the blocks below
# - Servers are used in a round-robin fashion by nginx
# - Add "backup" if you want to only use the mirror upon failure of the other mirrors
# - Use separate mirror server blocks to be able to use mirrors that have different paths to the package repos
upstream pacman_mirrors {
        server 127.0.0.1:8001;
        server 127.0.0.1:8002 backup;
        server 127.0.0.1:8003 backup;
}

# If you want to use an official mirror from /etc/pacman.d/mirrorlist like
# http://mirror.domain.example/path/to/repo/$repo/os/$arch
#
# the proxy_pass directive should look like this
# proxy_pass http://mirror.domain.example/path/to/repo$request_uri;
#
# Notice that $request_uri replaces the /$repo/os/$arch part of
# the mirror address. See more examples below.

# To update this list, goto a manjaro machine and run
# pacman-mirrors --geoip and look in /etc/pacman.d/mirrorlist

# Change your /etc/pacman.d/mirrorlist to this
# Server = http://pacman.mreschke.net:8080/manjaro/stable/$repo/$arch

# Edit /etc/pacman-mirrors.conf and set NoUpdate=True to disable autogeneration from systemd

# See https://repo.manjaro.org/ for updated mirrors, pick HTTP, sort by stable, ones with /manjro in path
# You must pick an HTTP mirror.  I tried HTTP and it doesn't even use the already cached file let alone save the cache

# Arch Mirror 1
server
{
        listen 127.0.0.1:8001;
        location / {
        proxy_pass http://repo.ialab.dsu.edu$request_uri;
        }
}

# Arch Mirror 2
server
{
        listen 127.0.0.1:8002;
        location / {
        #proxy_pass http://mirror.futureweb.be$request_uri;
        proxy_pass http://repo.ialab.dsu.edu$request_uri;
        }
}

# Arch Mirror 3
server
{
        listen 127.0.0.1:8003;
    location / {
        #proxy_pass https://mirror.math.princeton.edu$request_uri;
        proxy_pass http://mirrors.gigenet.com$request_uri;
        }
}