LinuxCommandLibrary

apk

Manage Alpine Linux packages

TLDR

Update repository indexes and upgrade all packages

$ apk upgrade [[-U|--update-cache]]
copy

Only update repository indexes
$ apk update
copy

Install a new package
$ apk add [package]
copy

Remove a package
$ apk del [package]
copy

Repair/Reinstall a package without modifying main dependencies
$ apk fix [package]
copy

Search for packages with a keyword in their name and list results with descriptions
$ apk search [[-v|--verbose]] [keyword]
copy

Search for packages with a keyword in their description
$ apk search [[-d|--description]] [keyword]
copy

Display information about a specific package
$ apk info [package]
copy

SYNOPSIS

apk [options] command [arguments...]

Common Commands:
  apk add <package>... - Installs specified packages.
  apk del <package>... - Removes specified packages.
  apk update - Updates the package index from repositories.
  apk upgrade - Upgrades all installed packages to their latest versions.
  apk search <pattern> - Searches for packages matching a pattern.
  apk info <package> - Displays information about an installed or available package.
  apk fix - Attempts to fix broken installations (e.g., missing dependencies).
  apk cache [clean|sync] - Manages the local package cache.

PARAMETERS

--allow-untrusted
    Permit installing packages without valid signatures.

--no-cache
    Do not use or create a package cache.

--no-network
    Prevent network access (useful for offline operations).

-q, --quiet
    Suppress most output messages.

-v, --verbose
    Increase output verbosity.

-i, --interactive
    Prompt for confirmation before proceeding.

--root
    Specify an alternate root directory for operations.

--repository
    Use a specific repository URL instead of configured ones.

--initdb
    Initialize the local package database if it doesn't exist.

DESCRIPTION

`apk` is the official package manager for Alpine Linux, a security-oriented, lightweight Linux distribution. Unlike other common package managers like apt or dnf, `apk` is designed from the ground up to be incredibly small, fast, and resource-efficient, making it ideal for containers, embedded systems, and minimal server environments.

It manages .apk packages, which are simple tar.gz archives containing compiled binaries, libraries, and metadata. `apk` handles dependency resolution, package installation, upgrades, and removal from both local repositories and official mirrors. Its simplicity contributes to Alpine's small footprint and fast boot times. By prioritizing minimalism, `apk` helps maintain Alpine's focus on a secure and compact base system, often resulting in Docker images that are orders of magnitude smaller than those built on other distributions.

CAVEATS

`apk` is exclusive to Alpine Linux and its derivatives. Packages for other distributions (e.g., .deb, .rpm) are incompatible. Alpine Linux uses Musl libc instead of the more common glibc, which means binaries compiled for other distributions will generally not run directly on Alpine without specific recompilation or compatibility layers. Its package repositories, while growing, are generally smaller than those of larger distributions.

PACKAGE REPOSITORIES

`apk` uses a list of repositories defined in /etc/apk/repositories. Each line in this file specifies a URL to an Alpine repository, allowing users to configure which package sources are used. This flexibility enables easy setup of local mirrors or custom repositories.

SECURITY MODEL

`apk` strongly emphasizes security. All official packages are cryptographically signed using RSA keys. `apk` verifies these signatures and package checksums during installation to ensure package integrity and authenticity, protecting against tampering and unauthorized modifications.

HISTORY

The development of Alpine Linux began around 2005 with a strong focus on security and small size. `apk` was created specifically for Alpine to fulfill its unique requirements for a lightweight and efficient package manager. Its design has evolved in tandem with Alpine's growth, particularly with the increasing adoption of containers, where `apk`'s minimal footprint and fast operations provide significant advantages. The move from uClibc to Musl libc for a more compliant and robust C library was a notable milestone in Alpine's history that `apk` seamlessly adapted to.

SEE ALSO

apt(8), dnf(8), pacman(8), zypper(8), opkg(8)

Copied to clipboard