apk
Manage Alpine Linux packages
TLDR
Update repository indexes and upgrade all packages
Only update repository indexes
Install a new package
Remove a package
Repair/Reinstall a package without modifying main dependencies
Search for packages with a keyword in their name and list results with descriptions
Search for packages with a keyword in their description
Display information about a specific package
SYNOPSIS
apk [options...] command [arguments...]
Common commands: add, del, info, search, update, upgrade
PARAMETERS
-v, --verbose
Verbose output
-q, --quiet
Quiet output
-p, --rootdir <dir>
Use <dir> as root (default: /)
-X, --repository <repo>
Add repository to search list
-U, --upgrade
Upgrade packages during install
-t, --test
Dry run, simulate actions
-f, --force-overwrite
Overwrite files conflicting with others
--allow-untrusted
Allow untrusted repositories
-a, --available
Show available packages
--cache-max-age <seconds>
Maximum age for cached index
DESCRIPTION
The apk command is the package manager for Alpine Linux, a lightweight, security-oriented distribution. It handles installation, removal, updating, and querying of software packages distributed as .apk archives. apk emphasizes speed, simplicity, and atomic transactions, using a database-driven approach with musl libc and BusyBox. It supports repositories defined in /etc/apk/repositories, fetches packages over HTTP/FTP, verifies checksums and signatures, and performs dependency resolution. Key features include virtual packages, world files for tracking installed packages (/var/lib/apk/world), and options for offline operation via local caches. Unlike deb/rpm-based managers, apk is designed for embedded and containerized environments like Docker, enabling minimal base images. It supports simultaneous upgrades without system downtime and conflict resolution via --force-overwrite. Usage is straightforward: update cache with apk update, then apk add packages. It's integral to Alpine's philosophy of reducing attack surface through fewer components.
CAVEATS
Exclusive to Alpine Linux; requires configured repositories in /etc/apk/repositories. Not compatible with other distros. Virtual packages may lead to unexpected dependencies. Use --no-cache to avoid disk usage in containers.
COMMON SUBCOMMANDS
add pkg: Install package(s).
del pkg: Remove package(s).
update: Refresh package index.
upgrade: Upgrade all packages.
info pkg: Show package details.
search term: Find packages.
CONFIGURATION
Main config: /etc/apk/apk-tools.conf. Repos: /etc/apk/repositories. Installed pkgs tracked in /var/lib/apk/world.
HISTORY
Developed by Natanael Copa in 2010 for Alpine Linux (formerly Alpine Edge), replacing opkg. Evolved with APKBUILD for building packages from source. Gained popularity post-2015 with Docker's Alpine images, emphasizing security and size. Version 2.x introduced atomic upgrades; current 3.x adds better signing and compression.


