The pacman module manages packages on Arch Linux systems using the pacman package manager.
Functions
packages
Install or remove pacman packages.
from pyinfra.operations import pacman
pacman.packages(
name = "Install development tools" ,
packages = [ "git" , "vim" ],
update = True ,
)
List of packages to ensure.
Whether the packages should be installed.
Run pacman -Sy before installing packages.
Run pacman -Su before installing packages.
Package versions can be pinned like pacman: <pkg>=<version>
Example
from pyinfra.operations import pacman
pacman.packages(
name = "Install Vim and a plugin" ,
packages = [ "vim-fugitive" , "vim" ],
update = True ,
)
update
Update pacman package database.
from pyinfra.operations import pacman
pacman.update(
name = "Update package database" ,
)
This operation is not idempotent - it will always execute.
upgrade
Upgrade all pacman packages.
from pyinfra.operations import pacman
pacman.upgrade(
name = "Upgrade all packages" ,
)
This operation is not idempotent - it will always execute.
Common Use Cases
System Setup
from pyinfra.operations import pacman
# Update package database
pacman.update(
name = "Update package database" ,
)
# Install base packages
pacman.packages(
name = "Install base development tools" ,
packages = [
"base-devel" ,
"git" ,
"vim" ,
"wget" ,
"curl" ,
],
)
Full System Upgrade
from pyinfra.operations import pacman
# Update and upgrade
pacman.packages(
name = "Perform full system upgrade" ,
packages = [],
update = True ,
upgrade = True ,
)
Development Environment
from pyinfra.operations import pacman
# Install development tools
pacman.packages(
name = "Install development environment" ,
packages = [
"base-devel" ,
"git" ,
"vim" ,
"tmux" ,
"python" ,
"python-pip" ,
"docker" ,
"docker-compose" ,
],
update = True ,
)
Web Server Setup
from pyinfra.operations import pacman
# Install web server stack
pacman.packages(
name = "Install NGINX and certbot" ,
packages = [
"nginx" ,
"certbot" ,
"certbot-nginx" ,
],
update = True ,
)
Desktop Environment
from pyinfra.operations import pacman
# Install Xorg and i3
pacman.packages(
name = "Install X server and i3 window manager" ,
packages = [
"xorg-server" ,
"xorg-xinit" ,
"i3-wm" ,
"i3status" ,
"dmenu" ,
"termite" ,
],
update = True ,
)
Arch-Specific Tips
Pacman supports package groups which install multiple related packages: from pyinfra.operations import pacman
# Install the base-devel group
pacman.packages(
name = "Install base development tools" ,
packages = [ "base-devel" ],
)
For AUR (Arch User Repository) packages, you’ll need to use a helper like yay or paru: from pyinfra.operations import server
# Install AUR helper (yay)
server.shell(
name = "Install yay AUR helper" ,
commands = [
"cd /tmp" ,
"git clone https://aur.archlinux.org/yay.git" ,
"cd yay" ,
"makepkg -si --noconfirm" ,
],
)
# Install AUR packages with yay
server.shell(
name = "Install AUR packages" ,
commands = [ "yay -S --noconfirm package-name" ],
)
Clean up old packages from cache: from pyinfra.operations import server
# Remove all cached packages
server.shell(
name = "Clean package cache" ,
commands = [ "pacman -Sc --noconfirm" ],
)
# Remove all cached packages and unused sync databases
server.shell(
name = "Clean all cache" ,
commands = [ "pacman -Scc --noconfirm" ],
)
Remove packages that were installed as dependencies but are no longer needed: from pyinfra.operations import server
# Remove orphaned packages
server.shell(
name = "Remove orphaned packages" ,
commands = [ "pacman -Rns $(pacman -Qtdq) --noconfirm || true" ],
)
Important Notes
Always run pacman -Sy (update) before installing packages to ensure you’re installing the latest versions and avoid partial upgrades.
Pacman uses the --noconfirm flag in pyinfra operations to enable non-interactive installations.