✦ For everyone, free.

Practical knowledge for real and everyday life

Home

APK Configuration

APK Configuration manages software packages in Alpine Linux, defining dependencies, installation paths, and system integration through metadata.

APK Configuration defines the settings and parameters that govern how the Alpine Package Keeper (APK) operates on an Alpine Linux system. It includes the directives that control package management behavior such as repository sources, package caching, key management for verification, and other operational options. The configuration determines how APK interacts with package repositories, manages dependencies, and installs, upgrades, or removes packages securely and efficiently.


Configuration File Location and Format

The primary APK configuration file is located at:

/etc/apk/repositories

This file lists the URLs or local paths of the package repositories that APK uses to fetch packages and metadata. Additionally, the main APK configuration options can be found or overridden in:

/etc/apk/apk.conf

The format of these files is plain text, with one repository URL per line in the repositories file, and key-value pairs in the apk.conf file.


Repository Configuration

Repository URLs

Repositories are specified as URLs or local paths, pointing to the location of APK package indices and packages. Example entries include:

http://dl-cdn.alpinelinux.org/alpine/v3.17/main
http://dl-cdn.alpinelinux.org/alpine/v3.17/community

Repositories can be HTTPS or HTTP URLs, or local file paths (e.g., /var/apk/localrepo).

Repository Priority and Mirrors

APK does not support priority ordering of repositories out-of-the-box, but mirrors can be chosen by listing preferred URLs first. When multiple repositories contain the same package, APK selects the first matching package found based on the order in the repositories file.


Key Management and Package Verification

APK uses GPG keys to verify the authenticity and integrity of packages. The keys are stored in:

/etc/apk/keys/

Each key file corresponds to a trusted public key used to check packages' signatures. APK configuration can specify which keys to trust, and when fetching packages, their signatures are validated against these keys to prevent tampering.


Configuration Options in apk.conf

The apk.conf file contains various parameters that control APK's behavior. Common options include:

  • cache_dir: Directory where downloaded packages and metadata are cached. Default is usually /var/cache/apk.
  • repositories: Alternative location or file specifying repositories.
  • http_timeout: Timeout for HTTP connections when fetching packages.
  • signature_level: Defines the strictness of signature verification (required, optional, none).
  • force_ipv4 / force_ipv6: Force use of a specific IP protocol version.
  • allow_untrusted: Allow installation of packages without valid signatures (not recommended).
  • cache_size: Maximum size of the package cache.

Example snippet from apk.conf:

cache_dir="/var/cache/apk"
signature_level="required"
http_timeout=30
allow_untrusted="false"

Environment Variables and Command-line Overrides

APK respects certain environment variables and command-line flags that can override configuration file settings for a particular execution. For example:

  • APK_CACHE_DIR: Overrides the cache directory.
  • APK_REPOSITORIES: Overrides repository list.
  • Command-line options such as --repository or --cache-dir provide temporary overrides without modifying config files.

Package Index and Cache Management

APK maintains a local cache of package indices and downloaded packages to optimize operations. The configuration controls:

  • Where this cache is stored (cache_dir).
  • How long metadata is valid before refreshing.
  • Whether to keep or clean cached packages after installation.

Proper configuration of cache settings affects network usage, speed, and disk space.


Custom Repositories and Private APK Configuration

APK Configuration supports defining private or custom repositories by adding their URLs or local paths to the repositories file. This enables organizations to maintain internal package feeds.

Additionally, custom keys must be added to /etc/apk/keys to allow secure verification of packages from these sources.


Summary of Key Configuration Files and Their Contents

File PathPurposeContent Example
/etc/apk/repositoriesDefines package repository URLs and pathshttp://dl-cdn.alpinelinux.org/alpine/v3.17/main
/etc/apk/apk.confGlobal APK behavior settingscache_dir="/var/cache/apk"
signature_level="required"
/etc/apk/keys/Contains trusted public keys for signature verificationalpine-devel@lists.alpinelinux.org-4a6a0840.rsa.pub

Practical Example of Configuration Files

/etc/apk/repositories:

http://dl-cdn.alpinelinux.org/alpine/v3.17/main
http://dl-cdn.alpinelinux.org/alpine/v3.17/community

/etc/apk/apk.conf:

cache_dir="/var/cache/apk"
signature_level="required"
http_timeout=30
allow_untrusted="false"
force_ipv4="false"

Additional Configuration Aspects

Proxy and Network Settings

APK can be configured to work behind HTTP proxies by setting environment variables such as HTTP_PROXY and HTTPS_PROXY. These are not set in APK configuration files directly but affect APK's network operations.

Logging and Debugging

APK supports verbose output and debugging via command-line flags (-v, -vv). While not configured via files, knowledge of this behavior is important for troubleshooting.


Summary

APK Configuration encompasses all settings that control how APK accesses repositories, verifies packages, manages caches, and behaves during package operations. It is primarily managed through /etc/apk/repositories for repository definitions, /etc/apk/apk.conf for behavioral parameters, and /etc/apk/keys/ for cryptographic verification. Proper configuration ensures secure, efficient, and reliable package management on Alpine Linux systems.