Alpine Linux apk Reference: Package Management, Repositories, and System Administration
Alpine's apk Is Not apt or dnf
Alpine Linux uses apk (Alpine Package Keeper) — a fast, straightforward package manager that's distinct from both apt and dnf. If you're coming from Ubuntu or RHEL, apk works similarly but with different flags and a much simpler dependency model.
This guide covers apk from daily operations to repository management, with enough context about Alpine's design philosophy to make sense of why things work the way they do.
Alpine Releases
Alpine follows a predictable release model:
| Branch | Description |
|---|---|
edge | Rolling release — latest software, less stability |
v3.20 | Latest stable (as of 2026) |
v3.19, v3.18 | Previous stable releases |
Alpine stable releases receive security and bug-fix updates for ~2 years. edge is used for active development. For servers, use a numbered stable release.
Core apk Operations
Installing Packages
# Install a package
apk add nginx
# Install multiple packages
apk add nginx curl bash git
# Install without caching index (for Dockerfiles)
apk add --no-cache nginx
# Install a specific version
apk add nginx=1.26.2-r0
# Install only if not already installed (idempotent)
apk add --no-cache nginx
# Simulate installation (dry run)
apk add --simulate nginx
Removing Packages
# Remove a package
apk del nginx
# Remove a package and its unused dependencies
apk del --purge nginx
# Remove packages that were auto-installed as dependencies
# and are no longer needed
apk del --purge $(apk info --rdepends nginx | tail -n +2)
Updating Packages
# Update the package index
apk update
# Upgrade all installed packages
apk upgrade
# Update index and upgrade in one command
apk update && apk upgrade
# Upgrade only a specific package
apk upgrade nginx
# Check for available upgrades without applying
apk version -v -l '<'
Searching and Querying
# Search for packages
apk search nginx
# Search by file (what package provides a file)
apk search -o /usr/sbin/nginx
# Show package info
apk info nginx
# Show package dependencies
apk info -d nginx
# List installed packages
apk info
# List files installed by a package
apk info -L nginx
# Check if a package is installed
apk info nginx 2>/dev/null && echo "installed" || echo "not installed"
# Show reverse dependencies (what depends on this package)
apk info -r nginx
# Show package version
apk version nginx
Repository Management
Alpine's repositories are configured in /etc/apk/repositories. Each line is a URL to a repository.
Default Repository Structure
cat /etc/apk/repositories
# Typical output for Alpine 3.20:
# https://dl-cdn.alpinelinux.org/alpine/v3.20/main
# https://dl-cdn.alpinelinux.org/alpine/v3.20/community
Alpine has three main repository categories:
- main: Core packages maintained by Alpine
- community: Broader package set, maintained by contributors
- testing: Unstable packages not yet in main/community (edge only)
Adding Repositories
# Add the community repo (if not already enabled)
echo "https://dl-cdn.alpinelinux.org/alpine/v3.20/community" >> /etc/apk/repositories
apk update
# Add the edge testing repo (for packages not in stable)
echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
apk update
# Install a package from edge/testing (using tag)
apk add some-package@testing
Repository Tags
Alpine supports repository tagging to pin packages to specific repos:
# In /etc/apk/repositories:
@edge https://dl-cdn.alpinelinux.org/alpine/edge/main
@community https://dl-cdn.alpinelinux.org/alpine/v3.20/community
@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing
# Install from a specific tagged repo
apk add postgresql@edge
apk add some-new-package@testing
Version Pinning and Holds
# Install and pin a specific version
apk add nginx=1.26.2-r0
# Pin using world file (persists across apk upgrade)
# The world file at /etc/apk/world lists all explicitly installed packages
cat /etc/apk/world
# To hold a package at its current version (prevent upgrade):
# Pin it in world with the exact version
apk add 'nginx=~1.26' # pin to 1.26.x series (fuzzy)
apk add 'nginx=1.26.2-r0' # pin to exact version
# Verify pinning
apk version nginx
The World File
Alpine tracks explicitly installed packages in /etc/apk/world. This file is what separates explicitly requested packages from auto-installed dependencies.
# View the world file
cat /etc/apk/world
# Reconstruct packages from world (useful for reproducing a system)
apk add $(cat /etc/apk/world)
# Sync the system to match world file exactly
# (installs missing, removes unlisted packages)
apk fix
Running Alpine as a Server
Network Configuration
Alpine uses /etc/network/interfaces for networking:
# Static IP configuration
cat > /etc/network/interfaces << 'EOF'
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.100/24
gateway 192.168.1.1
EOF
# DNS
echo "nameserver 1.1.1.1" > /etc/resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
# Apply network config
/etc/init.d/networking restart
Init System: OpenRC
Alpine uses OpenRC, not systemd. Service management is different:
# Start a service
rc-service nginx start
# Stop a service
rc-service nginx stop
# Enable on boot (add to default runlevel)
rc-update add nginx default
# Disable from boot
rc-update del nginx default
# List services and their runlevels
rc-update show
# Check service status
rc-service nginx status
# Restart
rc-service nginx restart
OpenRC runlevels:
boot— essential services (networking, logging)default— normal servicesnonetwork— services that run without network
Disk and Filesystem
# Alpine runs from RAM by default (diskless mode)
# For persistent install, use setup-alpine to install to disk
# Check disk usage
df -h
# Alpine's setup scripts handle common tasks:
setup-alpine # Full system setup wizard
setup-disk # Configure disk/partitions
setup-networking # Configure network
setup-apkrepos # Configure repositories
setup-sshd # Configure SSH
# Add a swap file
dd if=/dev/zero of=/swapfile bs=1M count=1024
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
Building Custom apk Packages
For packaging your own software:
# Install build tools
apk add alpine-sdk abuild
# Set up a build user
adduser -D builduser
addgroup builduser abuild
# Generate signing key
su - builduser -c "abuild-keygen -a -i"
# Create APKBUILD file
mkdir -p /home/builduser/myapp
cat > /home/builduser/myapp/APKBUILD << 'EOF'
pkgname=myapp
pkgver=1.0.0
pkgrel=0
pkgdesc="My application"
url="https://example.com"
arch="x86_64"
license="MIT"
depends="nginx"
source="myapp-$pkgver.tar.gz"
build() {
cd "$builddir"
make
}
package() {
cd "$builddir"
make DESTDIR="$pkgdir" install
}
EOF
# Build the package
cd /home/builduser/myapp
su - builduser -c "cd /home/builduser/myapp && abuild -r"
Common Alpine Server Packages
# Web server
apk add nginx
# Database
apk add postgresql postgresql-client
apk add mariadb mariadb-client
# Languages
apk add python3 py3-pip
apk add nodejs npm
apk add php83 php83-fpm
# Security
apk add openssh fail2ban
# Monitoring
apk add htop iotop sysstat
# Networking tools
apk add curl wget bind-tools tcpdump nmap
# File management
apk add rsync tar gzip
apk vs apt vs dnf Quick Reference
| Operation | apk | apt | dnf |
|---|---|---|---|
| Install | apk add pkg | apt install pkg | dnf install pkg |
| Remove | apk del pkg | apt remove pkg | dnf remove pkg |
| Update index | apk update | apt update | dnf check-update |
| Upgrade all | apk upgrade | apt upgrade | dnf upgrade |
| Search | apk search pkg | apt search pkg | dnf search pkg |
| Info | apk info pkg | apt show pkg | dnf info pkg |
| List files | apk info -L pkg | dpkg -L pkg | rpm -ql pkg |
| What provides | apk search -o /file | dpkg -S /file | dnf provides /file |
Alpine's apk is significantly faster than both apt and dnf due to its simpler dependency solver and the compact package format. For container images and resource-constrained systems, this speed difference is noticeable at scale.
Was this article helpful?
Linux Systems Engineer
Everything runs on Linux — I make sure it runs well. From kernel tuning to systemd debugging, I live in the terminal. If your server is misbehaving, I've probably seen that exact dmesg output before.
Related Articles
openSUSE and SUSE Linux Enterprise: YaST Administration and zypper Package Management
A practical guide to SUSE Linux administration — using YaST for system configuration, zypper for package management, managing repositories, and understanding the differences between openSUSE Leap, Tumbleweed, and SUSE Linux Enterprise.
Alpine Linux for Docker: Building Minimal, Secure Container Images
How to use Alpine Linux as a Docker base image effectively — understanding musl libc compatibility, multi-stage builds, layer optimization, and the security trade-offs versus glibc-based distributions.
openSUSE MicroOS and Transactional Updates: Atomic System Updates with Btrfs Snapshots
How openSUSE's transactional-update and Btrfs snapshot integration enables atomic, rollback-safe system updates — and how MicroOS takes this to a fully immutable, container-optimized OS.
RHEL 9 Performance Tuning: tuned, sysctl, and CPU/Memory Optimization
How to tune RHEL 9 performance using tuned profiles, sysctl parameters, CPU governors, NUMA topology, and memory settings — for database servers, web workloads, and latency-sensitive applications.
RHEL 9 Subscription Manager: Attaching Entitlements, Enabling Repos, and Going Offline
A practical guide to RHEL 9's subscription management — attaching entitlements, enabling the right repositories, creating local mirrors for air-gapped environments, and managing subscriptions at scale.
Migrating from CentOS to Rocky Linux: A Practical Conversion Guide
How to migrate existing CentOS 7/8 servers to Rocky Linux 8 or 9 using the migrate2rocky script — including pre-migration checks, the migration process itself, and post-migration validation steps.
More in Linux
View all →Linux Control Groups (cgroups V2): Limiting CPU And Memory For Production Workloads
If you're running production workloads without cgroup constraints, you're one runaway process away from a bad day. Here's everything you need to configure...
Rocky Linux 9 Server Hardening: Security Baseline from First Boot
A production security baseline for Rocky Linux 9 — covering SELinux configuration, firewalld rules, SSH hardening, auditd, AIDE integrity checking, and CIS Benchmark compliance checks.
Ubuntu 24.04 LTS Server Setup for Production: From Bare Metal to Hardened Baseline
A complete walkthrough for turning a fresh Ubuntu 24.04 LTS installation into a production-ready server — from initial SSH lockdown to swap configuration and kernel parameter tuning.
Ubuntu Zero-Downtime Patching: Unattended Upgrades, Livepatch, and USN Tracking
How to keep Ubuntu servers patched automatically without unplanned reboots — combining unattended-upgrades, Canonical Livepatch, and USN monitoring into a practical patching strategy.