pm module provides a unified interface for package management across different Linux distributions and operating systems. It automatically detects the system’s package manager and translates commands accordingly.
Requires
runtime::pm() from the runtime module to detect the package manager. Most operations require sudo privileges.Supported package managers
The module supports the following package managers:apt
Debian, Ubuntu, Mint
pacman
Arch Linux, Manjaro
dnf
Fedora, RHEL 8+
yum
CentOS, RHEL 7
zypper
openSUSE, SUSE
apk
Alpine Linux
brew
macOS, Linux
pkg
FreeBSD
xbps
Void Linux
nix
NixOS, any with Nix
Functions
pm::install(packages...)
pm::install(packages...)
Install one or more packages.Automatically translates to the appropriate command:
- apt:
sudo apt-get install -y - pacman:
sudo pacman -S --noconfirm - dnf:
sudo dnf install -y - brew:
brew install - etc.
packages...- One or more package names
pm::sync()
pm::sync()
Synchronize package database (update package lists).Translates to:
- apt:
sudo apt-get update - pacman:
sudo pacman -Sy - dnf:
sudo dnf check-update - brew:
brew update - etc.
pm::update()
pm::update()
Upgrade all installed packages.Translates to:
- apt:
sudo apt-get upgrade -y - pacman:
sudo pacman -Su --noconfirm - dnf:
sudo dnf upgrade -y - brew:
brew upgrade - etc.
pm::uninstall(packages...)
pm::uninstall(packages...)
Uninstall one or more packages.Translates to:
- apt:
sudo apt-get remove -y - pacman:
sudo pacman -R --noconfirm - dnf:
sudo dnf remove -y - brew:
brew uninstall - etc.
packages...- One or more package names
pm::search(query)
pm::search(query)
Search for packages matching a query.Translates to:
- apt:
apt-cache search - pacman:
pacman -Ss - dnf:
dnf search - brew:
brew search - etc.
query- Search term or regex
Usage examples
Basic package installation
System maintenance script
Conditional package installation
Search and install
Error handling
All functions return the exit code from the underlying package manager:Platform-specific notes
Homebrew (macOS/Linux)
Homebrew (macOS/Linux)
- Does not require sudo
- Best practice: run
brew updatebefore installing packages - Use
brew install --caskfor GUI applications (requires direct brew command)
APT (Debian/Ubuntu)
APT (Debian/Ubuntu)
- Runs with
-yflag (non-interactive) - Uses
apt-getinstead ofaptfor script stability pm::syncis equivalent toapt-get update
Pacman (Arch)
Pacman (Arch)
- Runs with
--noconfirmflag pm::syncupdates database only (doesn’t upgrade packages)- Use
pm::updateto upgrade packages
Nix
Nix
- Does not use sudo (user-level installation)
pm::searchusesnix-env -qaP- Package names may differ from other distributions