User:Wacek/brudnopis pacman/Tips and tricks
Aby zapoznać się z ogólnymi metodami poprawy elastyczności dostarczonych wskazówek lub samego pacmana, zobacz Core utilities i Bash.
Konserwacja
grep -Fxf
or grep -Fxvf
.Zobacz też System maintenance.
Wyświetlanie pakietów
Z wersją
Możesz chcieć uzyskać listę zainstalowanych pakietów wraz z ich wersjami, co jest przydatne podczas zgłaszania błędów lub omawiania zainstalowanych pakietów.
- Wyświetl listę wszystkich jawnie zainstalowanych pakietów:
pacman -Qe
. - Wyświetl listę wszystkich pakietów w package group o nazwie
group
:pacman -Sg group
- Lista wszystkich obcych pakietów (zwykle ręcznie pobranych i zainstalowanych lub pakietów usuniętych z repozytoriów):
pacman -Qm
. - Wyświetl listę wszystkich pakietów natywnych (zainstalowanych z bazy danych synchronizacji):
pacman -Qn
. - Wymień wszystkie jawnie zainstalowane pakiety natywne (tj. obecne w bazie danych synchronizacji), które nie są bezpośrednimi ani opcjonalnymi zależnościami:
pacman -Qent
. - Wyświetl listę pakietów według wyrażenia regularnego:
pacman -Qs regex
. - Wyświetl listę pakietów według wyrażenia regularnego z niestandardowym formatem wyjściowym (needs expac):
expac -s "%-30n %v" regex
.
Z rozmiarem
Ustalenie, które pakiety są największe, może być przydatne podczas próby zwolnienia miejsca na dysku twardym. Istnieją tutaj dwie opcje: pobierz rozmiar poszczególnych pakietów lub pobierz rozmiar pakietów i ich zależności.
Indywidualne pakiety
Następujące polecenie wyświetli listę wszystkich zainstalowanych pakietów i ich indywidualnych rozmiarów:
$ LC_ALL=C pacman -Qi | awk '/^Name/{name=$3} /^Installed Size/{print $4$5, name}' | sort -h
Pakiety i zależności
Aby wyświetlić listę rozmiarów pakietów wraz z ich zależnościami,
Aby wyświetlić rozmiar pobierania kilku pakietów (pozostaw packages
puste, aby wyświetlić listę wszystkich pakietów):
$ expac -S -H M '%k\t%n' packages
Aby wyświetlić jawnie zainstalowane pakiety, które nie znajdują się w bazie meta package ani w package group base-devel z rozmiarem i opisem:
$ expac -H M "%011m\t%-20n\t%10d" $(comm -23 <(pacman -Qqen | sort) <({ pacman -Qqg base-devel; expac -l '\n' '%E' base; } | sort -u)) | sort -n
Aby wyświetlić listę pakietów oznaczonych do aktualizacji wraz z ich rozmiarem do pobrania:
$ expac -S -H M '%k\t%n' $(pacman -Qqu) | sort -sh
Aby wyświetlić tylko opcjonalne zależności:
$ expac -S "%o" package
Według daty
Aby wyświetlić listę 20 ostatnio zainstalowanych pakietów z expac, uruchom:
$ expac --timefmt='%Y-%m-%d %T' '%l\t%n' | sort | tail -n 20
lub z sekundami od epoki (1970-01-01 UTC):
$ expac --timefmt=%s '%l\t%n' | sort -n | tail -n 20
Nie w określonej grupie, repozytorium lub metapakiecie
Wyświetl listę jawnie zainstalowanych pakietów, których nie ma w base meta package:
$ comm -23 <(pacman -Qqe | sort) <(expac -l '\n' '%E' base | sort)
Wyświetl listę jawnie zainstalowanych pakietów, których nie ma w base metapakiecie ani w package group base-devel:
$ comm -23 <(pacman -Qqe | sort) <({ pacman -Qqg base-devel; expac -l '\n' '%E' base; } | sort -u)
Wyświetl listę wszystkich zainstalowanych pakietów, które nie są wymagane przez inne pakiety i które nie znajdują się w base metapakiecie lub grupie pakietów base-devel:
$ comm -23 <(pacman -Qqt | sort) <({ pacman -Qqg base-devel; echo base; } | sort -u)
Jak wyżej, ale z opisami:
$ expac -H M '%-20n\t%10d' $(comm -23 <(pacman -Qqt | sort) <({ pacman -Qqg base-devel; echo base; } | sort -u))
Wyświetl listę wszystkich zainstalowanych pakietów, które „nie” znajdują się w określonym repozytorium „nazwa_repo”
$ comm -23 <(pacman -Qq | sort) <(pacman -Sql repo_name | sort)
Wyświetl listę wszystkich zainstalowanych pakietów, które znajdują się w repozytorium „nazwa_repo”:
$ comm -12 <(pacman -Qq | sort) <(pacman -Sql repo_name | sort)
Wymień wszystkie pakiety w Arch Linux ISO, które nie znajdują się w base pakiecie meta:
$ comm -23 <(curl https://gitlab.archlinux.org/archlinux/archiso/-/raw/master/configs/releng/packages.x86_64) <(expac -l '\n' '%E' base | sort)
combine
(instead of comm
) from the moreutils package which has a syntax that is easier to remember. See combine(1).Development packages
Aby wyświetlić listę wszystkich pakietów rozwojowych/niestabilnych, uruchom:
$ pacman -Qq | grep -Ee '-(bzr|cvs|darcs|git|hg|svn)$'
Przeglądanie pakietów
Aby przeglądać wszystkie zainstalowane pakiety z natychmiastowym podglądem każdego pakietu:
$ pacman -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pacman -Qil {} | less)'
Używa fzf do przedstawienia dwupanelowego widoku zawierającego listę wszystkich pakietów z informacjami o pakiecie pokazanymi po prawej stronie.
Wpisz litery, aby przefiltrować listę paczek; użyj klawiszy strzałek (or Ctrl-j
/Ctrl-k
) do nawigacji; naciśnij Enter
, aby zobaczyć informacje o paczce.
Aby przeglądać wszystkie pakiety obecnie znane „pacmanowi” (zarówno zainstalowane, jak i jeszcze niezainstalowane) w podobny sposób, używając fzf, użyj:
$ pacman -Slq | fzf --preview 'pacman -Si {}' --layout=reverse
Skróty klawiszy nawigacyjnych są takie same, chociaż Enter
nie będzie działał w ten sam sposób.
Wyświetlanie plików należących do pakietu z rozmiarem
Ten może się przydać, jeśli odkryłeś, że określony pakiet zajmuje ogromną ilość miejsca i chcesz dowiedzieć się, które pliki składają się na to najwięcej.
$ pacman -Qlq package | grep -v '/$' | xargs -r du -h | sort -h
Zidentyfikuj pliki, które nie należą do żadnego pakietu
Jeśli twój system zawiera przypadkowe pliki, które nie należą do żadnego pakietu (częsty przypadek, jeśli nie używasz menedżera pakietów do instalowania oprogramowania), możesz chcieć znaleźć takie pliki, aby je wyczyścić.
Jedną z metod jest użycie pacreport --unowned-files
jako użytkownika root z pacutils, który wyświetli między innymi listę nieposiadanych plików.
Innym jest wypisanie wszystkich interesujących plików i sprawdzenie ich pod kątem „pacmana”:
# find /etc /usr /opt | LC_ALL=C pacman -Qqo - 2>&1 >&- >/dev/null | cut -d ' ' -f 5-
Śledzenie nieposiadających plików utworzonych przez pakiety
Most systems will slowly collect several ghost files such as state files, logs, indexes, etc. through the course of usual operation.
pacreport
from pacutils can be used to track these files and their associations via /etc/pacreport.conf
(see pacreport(1) § FILES).
An example may look something like this (abridged):
/etc/pacreport.conf
[Options] IgnoreUnowned = usr/share/applications/mimeinfo.cache [PkgIgnoreUnowned] alsa-utils = var/lib/alsa/asound.state bluez = var/lib/bluetooth ca-certificates = etc/ca-certificates/trust-source/* dbus = var/lib/dbus/machine-id glibc = etc/ld.so.cache grub = boot/grub/* linux = boot/initramfs-linux.img pacman = var/lib/pacman/local update-mime-database = usr/share/mime/magic
Then, when using pacreport --unowned-files
as the root user, any unowned files will be listed if the associated package is no longer installed (or if any new files have been created).
Additionally, aconfmgr (aconfmgr-gitAUR) allows tracking modified and orphaned files using a configuration script.
Usuwanie nieużywanych pakietów (sierot)
Sieroty to pakiety, które zostały zainstalowane jako zależność i nie są już wymagane przez żaden pakiet.
Mogą gromadzić się w twoim systemie z czasem z powodu odinstalowywania pakietów przy użyciu pacman -R package
zamiast pacman -Rs package
, instalowania pakietów jako makedepends lub pakietów usuwających zależności w nowszych wersjach.
Do rekurencyjnego usuwania sierot i ich plików konfiguracyjnych:
# pacman -Qtdq | pacman -Rns -
Jeśli nie znaleziono sierot, wynikiem jest error: argument '-' specified with empty stdin
Jest to oczekiwane, ponieważ żadne argumenty nie zostały przekazane do pacman -Rns
.
-Qt
list only true orphans. To include packages which are optionally required by another package, pass the -t
flag twice (i.e., -Qtt
).pacman -Qtd
command to a pacman post-transaction hook to be notified if a transaction orphaned a package. This can be useful for being notified when a package has been dropped from a repository, since any dropped package will also be orphaned on a local installation (unless it was explicitly installed). To avoid any "failed to execute command" errors when no orphans are found, use the following command for Exec
in your hook: /usr/bin/bash -c "/usr/bin/pacman -Qtd || /usr/bin/echo '=> None found.'"
The package pacman-log-orphans-hookAUR provides such hook with a more verbose instructions.Wykrywanie większej liczby niepotrzebnych pakietów
W niektórych przypadkach powyższa metoda nie wykryje wszystkich możliwych niepotrzebnych pakietów. Np. cykle zależności, nadmierne zależności (spełnione więcej niż jeden raz), niektóre niejasne opcje itp.
Aby wykryć takie pakiety:
$ pacman -Qqd | pacman -Rsu --print -
Jeśli chcesz usunąć wszystkie pakiety z listy jednocześnie, uruchom polecenie bez argumentu --print
Usuwanie wszystkiego oprócz niezbędnych pakietów
Jeśli kiedykolwiek konieczne będzie usunięcie wszystkich pakietów z wyjątkiem pakietów podstawowych, jedną z metod jest ustawienie przyczyny instalacji nieistotnych jako zależność, a następnie usunięcie wszystkich niepotrzebnych zależności.
Po pierwsze, dla wszystkich pakietów „zainstalowanych jawnie” zmień przyczynę ich instalacji na „zainstalowane jako zależność”:
# pacman -D --asdeps $(pacman -Qqe)
Następnie zmień przyczynę instalacji na „jawnie zainstalowaną” tylko tych niezbędnych pakietów, których „nie” chcesz usunąć, aby uniknąć atakowania ich:
# pacman -D --asexplicit base linux linux-firmware
- Additional packages can be added to the above command in order to avoid being removed. See Installation guide#Install essential packages for more info on other packages that may be necessary for a fully functional base system.
- This will also select the bootloader's package for removal. The system should still be bootable, but the boot parameters might not be changeable without it.
Finally, follow the instructions in #Removing unused packages (orphans) to remove all packages that are "installed as a dependency".
Pobieranie listy zależności kilku pakietów
Zależności są sortowane alfabetycznie, a dublety są usuwane.
pacman -Qi
.$ LC_ALL=C pacman -Si packages | awk -F'[:<=>]' '/^Depends/ {print $2}' | xargs -n1 | sort -u
Alternatywnie, z expac:
$ expac -l '\n' %E -S packages | sort -u
Lista zmienionych plików kopii zapasowych
Aby wyświetlić listę plików konfiguracyjnych śledzonych przez pacmana jako podatnych na zmiany użytkownika (tj. plików wymienionych w macierzy kopii zapasowej PKGBUILD) i po otrzymaniu modyfikacji użytkownika, użyj następującego polecenia:
# pacman -Qii | awk '/^MODIFIED/ {print $2}'
Uruchomienie tego polecenia z uprawnieniami administratora zapewni, że dane wyjściowe będą zawierały pliki, które mogą być odczytywane tylko przez administratora (takie jak /etc/sudoers
).
Można tego użyć podczas wykonywania selektywnej kopii zapasowej systemu lub podczas próby replikacji konfiguracji systemu z jednego komputera na inny.
Wykonaj kopię zapasową bazy danych Pacmana
Do wykonania kopii zapasowej lokalnej bazy danych pacman można użyć następującego polecenia:
$ tar -cjf pacman_database.tar.bz2 /var/lib/pacman/local
Zapisz kopię zapasową pliku bazy danych pacman na jednym lub kilku nośnikach offline, takich jak pamięć USB, zewnętrzny dysk twardy lub płyta CD-R.
Bazę danych można przywrócić, przenosząc plik pacman_database.tar.bz2
do katalogu / i wykonując następujące polecenie:
# tar -xjvf pacman_database.tar.bz2
/etc/pakbak.conf
.Łatwo sprawdzaj dzienniki zmian
Gdy opiekunowie aktualizują pakiety, zatwierdzenia są często komentowane w użyteczny sposób. Użytkownicy mogą je szybko sprawdzić z wiersza poleceń, instalując pacologAUR. To narzędzie wyświetla ostatnie komunikaty o zatwierdzeniu pakietów z oficjalnych repozytoriów lub AUR, używając pacolog package
.
Instalacja i odzyskiwanie
Alternatywne sposoby pozyskiwania i przywracania pakietów.
Instalowanie pakietów z płyty CD/DVD lub pamięci USB
Aby pobrać pakiety lub grupy pakietów:
# cd ~/Packages # pacman -Syw --cachedir . base base-devel grub-bios xorg gimp # repo-add ./custom.db.tar.gz ./*
Pacman, który domyślnie odwołuje się do instalacji hosta, nie rozwiąże prawidłowo i nie pobierze istniejących zależności. W przypadkach, gdy potrzebne są wszystkie pakiety i zależności, zaleca się utworzenie tymczasowej pustej bazy danych i odwołanie się do niej za pomocą opcji --dbpath
:
# mkdir /tmp/blankdb # pacman -Syw --cachedir . --dbpath /tmp/blankdb base base-devel grub-bios xorg gimp # repo-add ./custom.db.tar.gz ./*
Następnie możesz nagrać katalog „Pakiety” na dysk optyczny (np. CD, DVD) lub przenieść go na dysk flash USB, zewnętrzny dysk twardy itp.
Żeby zainstalować:
1. Zamontuj nośniki:
W przypadku napędu optycznego:
# mount --mkdir /dev/sr0 /mnt/repo
W przypadku pamięci flash USB, dysku twardego itp.:
# mount --mkdir /dev/sdxY /mnt/repo
2. Edytuj pacman.conf
i dodaj to repozytorium „przed” innymi (np. extra, core itp.). To jest ważne. Nie wystarczy odkomentować tego na dole. W ten sposób zapewnia, że pliki z CD/DVD/USB mają pierwszeństwo przed tymi w standardowych repozytoriach:
/etc/pacman.conf
[custom] SigLevel = PackageRequired Server = file:///mnt/repo/Packages
3. Na koniec zsynchronizuj bazę danych „pacman”, aby móc korzystać z nowego repozytorium:
# pacman -Syu
Niestandardowe repozytorium lokalne
Użyj skryptu repo-add dołączonego do pacmana, aby wygenerować bazę danych dla osobistego repozytorium. Użyj repo-add --help
, aby uzyskać więcej informacji na temat jego użycia. Baza danych pakietu to plik tar, opcjonalnie skompresowany. Prawidłowe rozszerzenia to .db lub .files, po których następuje rozszerzenie archiwum .tar, .tar.gz, .tar.bz2, .tar.xz, .tar.zst lub .tar.Z. Plik nie musi istnieć, ale muszą istnieć wszystkie katalogi nadrzędne.
Aby dodać nowy pakiet do bazy danych lub zastąpić starą wersję istniejącego pakietu w bazie danych, uruchom:
$ repo-add /path/to/repo.db.tar.gz /path/to/package-1.0-1-x86_64.pkg.tar.zst
Baza danych i pakiety nie muszą znajdować się w tym samym katalogu podczas korzystania z „repo-add”, ale należy pamiętać, że podczas korzystania z „pacmana” z tą bazą danych powinny być razem. Przechowywanie wszystkich zbudowanych pakietów, które mają zostać uwzględnione w repozytorium w jednym katalogu, umożliwia również użycie rozszerzenia powłoki glob w celu dodania lub aktualizacji wielu pakietów jednocześnie:
$ repo-add /path/to/repo.db.tar.gz /path/to/*.pkg.tar.zst
Jeśli chcesz obsługiwać wiele architektur, należy podjąć środki ostrożności, aby zapobiec występowaniu błędów. Każda architektura powinna mieć własne drzewo katalogów:
$ tree ~/customrepo/ | sed "s/$(uname -m)/arch/g"
/home/archie/customrepo/ └── arch ├── customrepo.db -> customrepo.db.tar.xz ├── customrepo.db.tar.xz ├── customrepo.files -> customrepo.files.tar.xz ├── customrepo.files.tar.xz └── personal-website-git-b99cce0-1-arch.pkg.tar.zst 1 directory, 5 files
Plik wykonywalny repo-add sprawdza, czy pakiet jest odpowiedni. Jeśli tak nie jest, pojawią się komunikaty o błędach podobne do tego:
==> ERROR: '/home/archie/customrepo/arch/foo-arch.pkg.tar.zst' does not have a valid database archive extension.
repo-remove służy do usuwania pakietów z bazy danych pakietów, z wyjątkiem tego, że w wierszu poleceń podawane są tylko nazwy pakietów.
$ repo-remove /path/to/repo.db.tar.gz pkgname
Po utworzeniu lokalnej bazy danych repozytorium dodaj repozytorium do pacman.conf
dla każdego systemu, który ma korzystać z repozytorium. Przykład niestandardowego repozytorium znajduje się w pacman.conf
. Nazwa repozytorium to nazwa pliku bazy danych z pominiętym rozszerzeniem pliku. W przypadku powyższego przykładu nazwą repozytorium byłoby po prostu repo. Odwołaj się do lokalizacji repozytorium, używając adresu URL file://
lub przez FTP, używając ftp://localhost/path/to/directory.
Jeśli chcesz, dodaj niestandardowe repozytorium do listy nieoficjalnych repozytoriów użytkowników, aby społeczność mogła z niego skorzystać.
Jeśli zdarzy ci się uruchomić kilka urządzeń Arch w sieci LAN, możesz udostępniać pakiety, aby znacznie skrócić czas pobierania. Pamiętaj, że nie powinieneś udostępniać między różnymi architekturami (tj. i686 i x86_64), ponieważ napotkasz problemy.
Read-only cache
If you are looking for a quick solution, you can simply run a basic temporary webserver which other computers can use as their first mirror.
Przede wszystkim udostępnij bazy danych pacmana w katalogu, który będziesz obsługiwać:
# ln -s /var/lib/pacman/sync/*.db /var/cache/pacman/pkg/
Then start serving this directory. For example, with Python http.server module:
$ python -m http.server -d /var/cache/pacman/pkg/
http.server
listens on port 8000
of any interface. To use another port, or bind only to specific address, simply add a parameter and an argument:
$ python -m http.server -d /var/cache/pacman/pkg/ --bind 127.0.0.1 8080
Then edit /etc/pacman.d/mirrorlist
on each client machine to add this server as the top entry:
/etc/pacman.d/mirrorlist
Server = http://server-ip:port ...
/repos/$repo/os/$arch
to this custom server like for other entries, as this hierarchy does not exist and therefore queries will fail.If looking for a more standalone solution, darkhttpd offers a very minimal webserver. Replace the previous python
command with e.g.:
$ sudo -u http darkhttpd /var/cache/pacman/pkg --no-server-id
You could also run darkhttpd as a systemd service for convenience: see Systemd#Writing unit files.
miniserve, a web small server written in Rust, can also be used:
$ miniserve /var/cache/pacman/pkg
Then edit /etc/pacman.d/mirrorlist
as above with the first url miniserve is available at.
If you are already running a web server for some other purpose, you might wish to reuse that as your local repository server instead. For example, if you already serve a site with nginx, you can add an nginx server block listening on port 8080:
/etc/nginx/nginx.conf
server { listen 8080; root /var/cache/pacman/pkg; server_name myarchrepo.localdomain; try_files $uri $uri/; }
Remember to restart nginx.service
after making this change.
Overlay mount of read-only cache
It is possible to use one machine on a local network as a read-only package cache by overlay mounting its /var/cache/pacman/pkg
directory. Such a configuration is advantageous if this server has installed on it a reasonably comprehensive selection of up-to-date packages which are also used by other boxes. This is useful for maintaining a number of machines at the end of a low bandwidth upstream connection.
As an example, to use this method:
# mkdir /tmp/remote_pkg /mnt/workdir_pkg /tmp/pacman_pkg # sshfs remote_username@remote_pkgcache_addr:/var/cache/pacman/pkg /tmp/remote_pkg -C # mount -t overlay overlay -o lowerdir=/tmp/remote_pkg,upperdir=/var/cache/pacman/pkg,workdir=/mnt/workdir_pkg /tmp/pacman_pkg
/tmp/pacman_pkg
overlay directory gives errors, e.g., "Stale file handle", try overlay mounting with options -o redirect_dir=off -o index=off
.After this, run pacman using the option --cachedir /tmp/pacman_pkg
, e.g.:
# pacman -Syu --cachedir /tmp/pacman_pkg
Distributed read-only cache
There are Arch-specific tools for automatically discovering other computers on your network offering a package cache. Try pacredir, pacserve, pkgdistcacheAUR, or paclanAUR. pkgdistcache uses Avahi instead of plain UDP which may work better in certain home networks that route instead of bridge between WiFi and Ethernet.
Historically, there was PkgD and multipkg, but they are no longer maintained.
Read-write cache
In order to share packages between multiple computers, simply share /var/cache/pacman/
using any network-based mount protocol. This section shows how to use SSHFS to share a package cache plus the related library-directories between multiple computers on the same local network. Keep in mind that a network shared cache can be slow depending on the file-system choice, among other factors.
First, install any network-supporting filesystem packages: sshfs, curlftpfs, samba or nfs-utils.
- To use sshfs, 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.
/var/cache/pacman/pkg
or any of its ancestors (e.g., /var
) a symlink. Pacman expects these to be directories. When pacman re-installs or upgrades itself, it will remove the symlinks and create empty directories instead. However during the transaction pacman relies on some files residing there, hence breaking the update process. Refer to FS#50298 for further details.two-way with rsync
Another approach in a local environment is rsync. Choose a server for caching and enable the rsync daemon. On clients synchronize two-way with this share via the rsync protocol. Filenames that contain colons are no problem for the rsync protocol.
Draft example for a client, using uname -m
within the share name ensures an architecture-dependent sync:
# rsync rsync://server/share_$(uname -m)/ /var/cache/pacman/pkg/ ... # pacman ... # paccache ... # rsync /var/cache/pacman/pkg/ rsync://server/share_$(uname -m)/ ...
Dynamic reverse proxy cache using nginx
nginx can be used to proxy package requests to official upstream mirrors and cache the results to the local disk. All subsequent requests for that package will be served directly from the local cache, minimizing the amount of internet traffic needed to update a large number of computers.
In this example, the cache server will run at http://cache.domain.example:8080/
and store the packages in /srv/http/pacman-cache/
.
Install nginx on the computer that is going to host the cache. Create the directory for the cache and adjust the permissions so nginx can write files to it:
# mkdir /srv/http/pacman-cache # chown http:http /srv/http/pacman-cache
Use the nginx pacman cache config as a starting point for /etc/nginx/nginx.conf
. Check that the resolver
directive works for your needs. In the upstream server blocks, configure the proxy_pass
directives with addresses of official mirrors, see examples in the configuration file about the expected format. Once you are satisfied with the configuration file start and enable nginx.
In order to use the cache each Arch Linux computer (including the one hosting the cache) must have the following line at the top of the mirrorlist
file:
/etc/pacman.d/mirrorlist
Server = http://cache.domain.example:8080/$repo/os/$arch ...
paccache
(which is provided by pacman-contrib) can be used to automate this using retention criteria of your choosing. For example, find /srv/http/pacman-cache/ -type d -exec paccache -v -r -k 2 -c {} \;
will keep the last 2 versions of packages in your cache directory.Pacoloco proxy cache server
Pacoloco is an easy-to-use proxy cache server for pacman repositories. It also allows automatic prefetching of the cached packages.
It can be installed as pacoloco. Open the configuration file and add pacman mirrors:
/etc/pacoloco.yaml
port: 9129 repos: mycopy: urls: - http://mirror.lty.me/archlinux - http://mirrors.kernel.org/archlinux
Restart pacoloco.service
and the proxy repository will be available at http://myserver:9129/repo/mycopy
.
Flexo proxy cache server
Flexo is yet another proxy cache server for pacman repositories. Flexo is available as flexo-gitAUR. Once installed, start the flexo.service
unit.
Flexo runs on port 7878
by default. Enter Server = http://myserver:7878/$repo/os/$arch
to the top of your /etc/pacman.d/mirrorlist
so that pacman downloads packages via Flexo.
Synchronize pacman package cache using synchronization programs
Use Syncthing or Resilio Sync to synchronize the pacman cache directories (i.e. /var/cache/pacman/pkg
).
Preventing unwanted cache purges
By default, pacman -Sc
removes package tarballs from the cache that correspond to packages that are not installed on the machine the command was issued on. Because pacman cannot predict what packages are installed on all machines that share the cache, it will end up deleting files that should not be.
To clean up the cache so that only outdated tarballs are deleted:
/etc/pacman.conf
[options] CleanMethod = KeepCurrent
Recreate a package from the file system
To recreate a package from the file system, use fakepkgAUR. Files from the system are taken as they are, hence any modifications will be present in the assembled package. Distributing the recreated package is therefore discouraged; see ABS and Arch Linux Archive for alternatives.
List of installed packages
Keeping a list of all explicitly installed packages can be useful to backup a system or quicken the installation of a new one:
$ pacman -Qqe > pkglist.txt
- With option
-t
, the packages already required by other explicitly installed packages are not mentioned. If reinstalling from this list they will be installed but as dependencies only. - With option
-n
, foreign packages (e.g. from AUR) would be omitted from the list. - Use
comm -13 <(pacman -Qqdt | sort) <(pacman -Qqdtt | sort) > optdeplist.txt
to also create a list of the installed optional dependencies which can be reinstalled with--asdeps
. - Use
pacman -Qqem > foreignpkglist.txt
to create the list of AUR and other foreign packages that have been explicitly installed.
To keep an up-to-date list of explicitly installed packages (e.g. in combination with a versioned /etc/
), you can set up a hook. Example:
[Trigger] Operation = Install Operation = Remove Type = Package Target = * [Action] When = PostTransaction Exec = /bin/sh -c '/usr/bin/pacman -Qqe > /etc/pkglist.txt'
Install packages from a list
To install packages from a previously saved list of packages, while not reinstalling previously installed packages that are already up-to-date, run:
# pacman -S --needed - < pkglist.txt
However, it is likely foreign packages such as from the AUR or installed locally are present in the list. To filter out from the list the foreign packages, the previous command line can be enriched as follows:
# pacman -S --needed $(comm -12 <(pacman -Slq | sort) <(sort pkglist.txt))
Eventually, to make sure the installed packages of your system match the list and remove all the packages that are not mentioned in it:
# pacman -Rsu $(comm -23 <(pacman -Qq | sort) <(sort pkglist.txt))
Listing all changed files from packages
If you are suspecting file corruption (e.g. by software/hardware failure), but are unsure if files were corrupted, you might want to compare with the hash sums in the packages. This can be done with pacutils:
# paccheck --md5sum --quiet
For recovery of the database see #Restore pacman's local database. The mtree
files can also be extracted as .MTREE
from the respective package files.
Reinstalling all packages
To reinstall all native packages, use:
# pacman -Qqn | pacman -S -
Foreign (AUR) packages must be reinstalled separately; you can list them with pacman -Qqm
.
Pacman preserves the installation reason by default.
--overwrite=*
, though this should be an absolute last resort. See System maintenance#Avoid certain pacman commands.Restore pacman's local database
See pacman/Restore local database.
Recovering a USB key from existing install
If you have Arch installed on a USB key and manage to mess it up (e.g. removing it while it is still being written to), then it is possible to re-install all the packages and hopefully get it back up and working again (assuming USB key is mounted in /newarch
)
# pacman -S $(pacman -Qq --dbpath /newarch/var/lib/pacman) --root /newarch --dbpath /newarch/var/lib/pacman
Viewing a single file inside a .pkg file
For example, if you want to see the contents of /etc/systemd/logind.conf
supplied within the systemd package:
$ bsdtar -xOf /var/cache/pacman/pkg/systemd-250.4-2-x86_64.pkg.tar.zst etc/systemd/logind.conf
Or you can use vim to browse the archive:
$ vim /var/cache/pacman/pkg/systemd-250.4-2-x86_64.pkg.tar.zst
Find applications that use libraries from older packages
Already running processes do not automatically notice changes caused by updates. Instead, they continue using old library versions. That may be undesirable, due to potential issues related to security vulnerabilities or other bugs, and version incompatibility.
Processes depending on updated libraries may be found using either htop, which highlights the names of the affected programs, or with a snippet based on lsof, which also prints the names of the libraries:
# lsof +c 0 | grep -w DEL | awk '1 { print $1 ": " $NF }' | sort -u
This solution will only detect files, that are normally kept opened by running processes, which basically limits it to shared libraries (.so
files). It may miss some dependencies, like those of Java or Python applications.
Installing only content in required languages
Many packages attempt to install documentation and translations in several languages. Some programs are designed to remove such unnecessary files, such as localepurgeAUR, which runs after a package is installed to delete the unneeded locale files. A more direct approach is provided through the NoExtract
directive in pacman.conf
, which prevent these files from ever being installed.
The example below installs English (US) files, or none at all:
/etc/pacman.conf
NoExtract = usr/share/help/* !usr/share/help/C/* NoExtract = usr/share/gtk-doc/html/* NoExtract = usr/share/locale/* usr/share/X11/locale/*/* usr/share/i18n/locales/* opt/google/chrome/locales/* !usr/share/X11/locale/C/* NoExtract = !usr/share/X11/locale/compose.dir !usr/share/X11/locale/iso8859-1/* NoExtract = !*locale*/en*/* !usr/share/*locale*/locale.* NoExtract = !usr/share/*locales/en_?? !usr/share/*locales/i18n* !usr/share/*locales/iso* NoExtract = usr/share/i18n/charmaps/* !usr/share/i18n/charmaps/UTF-8.gz !usr/share/i18n/charmaps/ANSI_X3.4-1968.gz NoExtract = !usr/share/*locales/trans* NoExtract = !usr/share/*locales/C !usr/share/*locales/POSIX NoExtract = usr/share/man/* !usr/share/man/man* NoExtract = usr/share/vim/vim*/lang/* NoExtract = usr/lib/libreoffice/help/en-US/* NoExtract = usr/share/kbd/locale/* NoExtract = usr/share/*/translations/*.qm usr/share/*/nls/*.qm usr/share/qt/phrasebooks/*.qph usr/share/qt/translations/*.pak !*/en-US.pak # Qt apps NoExtract = usr/share/*/locales/*.pak opt/*/locales/*.pak usr/lib/*/locales/*.pak !*/en-US.pak # Electron apps NoExtract = opt/onlyoffice/desktopeditors/dictionaries/* !opt/onlyoffice/desktopeditors/dictionaries/en_US/* NoExtract = opt/onlyoffice/desktopeditors/editors/web-apps/apps/*/main/locale/* !*/en.json NoExtract = opt/onlyoffice/desktopeditors/editors/web-apps/apps/*/main/resources/help/*/* !*/help/en/* NoExtract = opt/onlyoffice/desktopeditors/editors/web-apps/apps/*/main/resources/symboltable/* !*/en.json NoExtract = opt/onlyoffice/desktopeditors/editors/web-apps/apps/documenteditor/forms/locale/* !*/en.json NoExtract = opt/onlyoffice/desktopeditors/editors/web-apps/apps/spreadsheeteditor/main/resources/formula-lang/* !*/en.json !*/en_desc.json NoExtract = opt/onlyoffice/desktopeditors/converter/empty/*/* !opt/onlyoffice/desktopeditors/converter/empty/en-US/* NoExtract = usr/share/ibus/dicts/emoji-*.dict !usr/share/ibus/dicts/emoji-en.dict
Installing packages on bad connection
When trying to install a package from a bad connection (e.g. a train using a cell phone), use the --disable-download-timeout
option to lessen the chance of receiving errors such as:
error: failed retrieving file […] Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds
or
error: failed retrieving file […] Operation timed out after 10014 milliseconds with 0 out of 0 bytes received
Performance
Download speeds
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 enabling parallel downloads, or by using a different application to download packages, instead of pacman's built-in file downloader.
In all cases, make sure you have the latest pacman before doing any modifications.
# pacman -Syu
Powerpill
Powerpill is a pacman wrapper that uses parallel and segmented downloading to try to speed up downloads for pacman.
wget
This is also very handy if you need more powerful proxy settings than pacman's built-in capabilities.
To use wget
, first install the wget package then modify /etc/pacman.conf
by uncommenting the following line in the [options]
section:
XferCommand = /usr/bin/wget --passive-ftp --show-progress -c -q -N %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.
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
See aria2c(1) § OPTIONS for used aria2c options.
-d, --dir
: The directory to store the downloaded file(s) as specified by pacman.-o, --out
: The output file name(s) of the downloaded file(s).%o
: Variable which represents the local filename(s) as specified by pacman.%u
: Variable which represents the download URL as specified by pacman.
Other applications
There are other downloading applications that you can use with pacman. Here they are, and their associated XferCommand settings:
snarf
:XferCommand = /usr/bin/snarf -N %u
lftp
:XferCommand = /usr/bin/lftp -c pget %u
axel
:XferCommand = /usr/bin/axel -n 2 -v -a -o %o %u
hget
:XferCommand = /usr/bin/hget %u -n 2 -skip-tls false
(please read the documentation on the Github project page for more info)saldl
:XferCommand = /usr/bin/saldl -c6 -l4 -s2m -o %o %u
(please read the documentation on the project page for more info)
Utilities
- Lostfiles — Script that identifies files not owned by any package.
- pacutils — Helper library for libalpm based programs.
- pkgfile — Tool that finds what package owns a file.
- pkgtools — Collection of scripts for Arch Linux packages.
- pkgtop — Interactive package manager and resource monitor designed for the GNU/Linux.
- Powerpill — Uses parallel and segmented downloading through aria2 and Reflector to try to speed up downloads for pacman.
- repoctl — Tool to help manage local repositories.
- repose — An Arch Linux repository building tool.
- snap-pac — Make pacman automatically use snapper to create pre/post snapshots like openSUSE's YaST.
- vrms-arch — A virtual Richard M. Stallman to tell you which non-free packages are installed.
Graphical
- Apper — Qt 5 application and package manager using PackageKit written in C++. Supports AppStream metadata.
- Deepin App Store — Third party app store for DDE built with DTK, using PackageKit. Supports AppStream metadata.
- Discover — Qt 5 application manager using PackageKit written in C++/QML. Supports AppStream metadata, Flatpak and firmware updates.
- GNOME PackageKit — GTK 3 package manager using PackageKit written in C.
- GNOME Software — GTK 3 application manager using PackageKit written in C. Supports AppStream metadata, Flatpak and firmware updates.
- pcurses — Curses TUI pacman wrapper written in C++.
- tkPacman — Tk pacman wrapper written in Tcl.