Professional Documents
Culture Documents
org/wiki/Package_management
Package management
Contents
Overview
Add a Package
Remove a Package
Information on Packages
apk info
Listing installed packages
apk policy
Additional apk Commands
Local Cache
Overview
Enabling Local Cache with current releases
Cache maintenance
Removing older packages
Download missing packages
Delete and download in one step
Automatically Cleaning Cache on Reboot
Special Caching Configurations
Enabling Local Cache on HDD installs
Local Cache on tmpfs volumes
Manually Enabling Local Cache (required for releases prior to v2.3)
Advanced APK Usage
Holding a specific package back
Table of comparison with other Linux/Unix-like OSes for packages
1 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
Because Alpine
Linux is designed Troubleshooting
to run from RAM, "apk-tools is old"
package External Links
management
involves two
phases:
apk is the tool used to install, upgrade, or delete software on a running system.
lbu is the tool used to capture the data necessary to restore a system to a previously configured state.
This page documents the apk tool (https://git.alpinelinux.org/apk-tools/) - See the Alpine Local Backup page for the lbu tool.
Overview
The apk tool supports the following operations:
The packages are stored in one or more repositories. A repository is simply a directory with a collection of *.apk files. The
2 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
directory must include a special index file, named APKINDEX.tar.gz to be considered a repository.
The apk utility can install packages from multiple repositories. The list of repositories to check is stored in
/etc/apk/repositories, one repository per line. If you booted from a USB stick (/media/sda1) or CD-ROM
(/media/cdrom), your repository file probably looks something like this:
Contents of /etc/apk/repositories
/media/sda1/apks/
In addition to local repositories, the apk utility uses busybox wget to fetch packages using http:, https: or ftp: protocols. The
following is a valid repository file:
Contents of /etc/apk/repositories
/media/sda1/apks
http://dl-3.alpinelinux.org/alpine/v2.6/main
https://dl-3.alpinelinux.org/alpine/v2.6/main
ftp://dl-3.alpinelinux.org/alpine/v2.6/main
Repository pinning
You can specify additional "tagged" repositories in /etc/apk/repositories:
Contents of /etc/apk/repositories
http://nl.alpinelinux.org/alpine/v3.7/main
http://nl.alpinelinux.org/alpine/v3.7/community
@edge http://nl.alpinelinux.org/alpine/edge/main
@edgecommunity http://nl.alpinelinux.org/alpine/edge/community
@testing http://nl.alpinelinux.org/alpine/edge/testing
Apk will now by default only use the untagged repositories, but adding a tag to specific package:
1. will prefer the repository with that tag for the named package, even if a later version of the package is available in another
repository
2. allows pulling in dependencies for the tagged package from the tagged repository (though it prefers to use untagged
repositories to satisfy dependencies if possible)
3 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
By default, the apk utility will use the system repositories for all operations. This behavior can be overridden by the following
options:
--repositories-file
Override the system repositories by specifying a repositories file.
REPOFILE
Specify a supplemental repository that will be used in addition to the
-X|--repository REPO
system repositories. This option can be provided multiple times.
apk update
Adding the --update-cache, or for short -U switch to another apk command, as in apk --update-cache
upgrade or apk -U add ..., the command has the same effect as first running apk update before the other apk
command.
Tip: With remote repositories, it is a good idea to always do an update right before doing an upgrade
or add command. That way the command will install the latest available packages.
Add a Package
Use add to install packages from a repository. Any necessary dependencies are also installed. If you have multiple
repositories, the add command installs the newest package.
If you only have the main repository enabled in your configuration, apk will not include packages from the other repositories.
To install a package from the edge/testing repository without changing your repository configuration file, use the command
below. This will tell apk to use that particular repository.
Note: Be careful when using third-party or the testing repository. Your system can go down.
4 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
Note that multiple packages can be given. When installing a local package, all dependencies should also be specified. For
example:
Remove a Package
Use del to remove a package (and dependencies that are no longer needed.)
apk update
apk upgrade
apk -U upgrade
Here is an example, showing the procedure on a system that has several additional repositories pinned:
# apk update
fetch http://dl-3.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-3.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
fetch http://dl-3.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-3.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-3.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
v3.6.2-191-gf98d79930f [http://dl-3.alpinelinux.org/alpine/v3.6/main]
v3.6.2-190-ga5d68c47df [http://dl-3.alpinelinux.org/alpine/v3.6/community]
v3.6.0-4618-g0bf77c9821 [http://dl-3.alpinelinux.org/alpine/edge/main]
v3.6.0-4605-g85ed51dd83 [http://dl-3.alpinelinux.org/alpine/edge/community]
v3.6.0-4624-g11f1b9c8ab [http://dl-3.alpinelinux.org/alpine/edge/testing]
OK: 20118 distinct packages available
# apk upgrade
(1/2) Upgrading extra-cmake-modules@testing (5.38.0-r0 -> 5.39.0-r0)
(2/2) Upgrading extra-cmake-modules-doc@testing (5.38.0-r0 -> 5.39.0-r0)
5 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
Executing mdocml-apropos-1.14.1-r0.trigger
OK: 2635 MiB in 803 packages
To upgrade only specific packages, use the -u or --upgrade option of the add command:
apk update
apk add --upgrade busybox
To upgrade to a newer release, refer to the corresponding release notes and Upgrading_Alpine.
It becomes possible to update the boot files, though, if using a boot device that is writable and has been prepared with
setup-bootable.
However, even then, the kernel, with its modules and firmware files, can still not be updated directly through regular packages
updates. Instead, there is the update-kernel script that can generate initfs images and install them together with upgraded
kernels.
This package is required for the generation of the initial filesystem used during boot.
▪ Additional initfs features that are missing in the default configuration, like the btrfs filesystem support (at the
time of writing, to allow loading .apkovl configs and package cache during boot), may be enabled in
/etc/mkinitfs/mkinitfs.conf.
▪ Available initfs features may be listed with ls /etc/mkinitfs/features.d
ls /etc/mkinitfs/features.d
apk add nano
nano /etc/mkinitfs/mkinitfs.conf
lbu commit
update-kernel /media/sdXY/boot/
▪ An update-kernel run needs at least 8 GB free ram memory to avoid a broken modloop-image.
▪ See update-kernel --help for options to manually add additional module or firmware packages.
6 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
The return format is Package-Version. Omit Version for apk add Package
Examples:
apk search -v
▪ To list all packages that list NTP as part of their description, use the -d or --description option:
Information on Packages
apk info
The info command provides information on the contents of packages, their dependencies, and which files belong to a package.
For a given package, each element can be chosen (for example, -w to show just the webpage information), or all information
displayed with the -a command.
Example:
zlib-1.2.5-r1 description:
A compression/decompression Library
zlib-1.2.5-r1 webpage:
http://zlib.net
7 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
atop-1.25-r0
zlib-1.2.5-r1 contains:
lib/libz.so.1.2.5
lib/libz.so.1
lib/libz.so
zlib-1.2.5-r1 triggers:
Tip: The info command is also useful to determine which package a file belongs to. For example:
will display
apk info
To list all installed packages in alphabetical order, with a description of each, do:
The apk tool does not have a subcommand to list manually-installed packages that do not have reverse dependencies. To get
this information on a traditional system that is not using lbu, try this script. Note that this approach will also list core packages
like alpine-base that should not be removed.
#!/bin/sh
apk info | grep -ve '-doc$' | sort | while read pkg
do
rdep=`apk info -qr "$pkg"`
[ -z "$rdep" ] && echo $pkg
done
apk policy
To display the repository a package was installed from and will be updated from, plus any tagged or enabled repositories
8 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
For example:
Local Cache
Overview
To have the packages available during boot, apk can keep a cache of installed packages on a local disk.
Added packages can then be automatically (re-)installed from local media into RAM when booting, without requiring, and
even before there is a network connection.
The cache can be stored on any writable media, or at the same location as the .apkovl file from the local backup utility lbu.
setup-apkcache
The script creates a symlink named /etc/apk/cache that points to the cache directory.
Cache maintenance
9 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
The older versions of packages can be removed with the clean command.
Contents of /etc/local.d/cache.stop
#!/bin/sh
Tip: Usually the only time you need to reboot is when things have gone horribly wrong; so this is a
"best effort" to cover forgetting to sync the cache; It is much better to run sync immediately after
adding or upgrading packages.
Note: Custom shutdown commands were formerly added to a /etc/conf.d/local; but that method is
now deprecated.
10 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
mkdir -p /var/cache/apk
ln -s /var/cache/apk /etc/apk/cache
NOTE: apk is coded to ignore tmpfs caches, and this is correct behaviour in most instances. Using tmpfs as a package cache
can consume large amounts of system memory if you install a lot of packages, possibly resulting in a crashed system. You can
limit this by restricting the size of your cache to a small number (128M in the example below).
To do it, you need to create an image inside which your cache can live. We do this by creating an image file, formatting it with
ext2, and mounting it at /etc/apk/cache.
1. Create a cache directory on the storage device where you keep the lbu backups (typically, /dev/sda1.)
mkdir /media/sda1/cache
Tip: If you get an error that says "mkdir: can't create directory '/media/usbdisk/cache': Read-only file
system", then you probably need to remount your disk read-write temporarily. Try
11 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
ln -s /media/sda1/cache /etc/apk/cache
2. Run an lbu commit to save the change (/etc/apk/cache is in /etc and is automatically backed up.)
lbu commit
Now whenever you run an apk command that pulls a new package from a remote repository, the package is stored on your
local media. On startup, Alpine Linux will check the local cache for new packages, and will install them if available.
or
after which a
apk upgrade
will upgrade the entire system, keeping the asterisk package at the 1.6.0 or lower level
12 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
You can also use "fuzzy" version matching to pin the version to a major/minor release. For example:
will match any version of asterisk that starts with 1.6 (such as 1.6.0.21-r0 or 1.6.9.31-r9) <ref>Alpine source commit message
(https://git.alpinelinux.org/apk-tools/commit/?id=693b4bcdb0f22904a521a7c8ac4f13e697dc4d71)</ref>
If you desire deterministic, repeatable package installation (such as with containerized environments) via package pinning, it is
important to understand your package repo's version retention rules. For example, most Alpine package repos contain an
"edge" branch, which may drop package versions that are not deemed fit to make it into a stable branch. This means that
pinning to a version on the edge branch may stop working after the package version is revoked from the repo. Always pin to a
package version that is intended for your current Alpine Linux version.
Troubleshooting
"apk-tools is old"
apk update, apk upgrade or apk add may report the following:
WARNING: This apk-tools is OLD! Some packages might not function properly
This may happen if you are running Alpine Linux stable version with a certain edge/main, edge/community or testing
package(s) also installed. One resolution is to consider upgrading apk-tools (https://pkgs.alpinelinux.org/
packages?name=apk-tools&branch=edge&repo=&arch=x86_64&maintainer=). If edge is already tagged
(https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management#Repository_pinning) in your repositories, then try:
13 av 14 2022-01-22 10:19
Package management - Alpine Linux https://wiki.alpinelinux.org/wiki/Package_management
External Links
▪ 10 Alpine Linux apk Command Examples (https://www.cyberciti.biz/faq/10-alpine-linux-apk-command-example
s/) Vivek Gite 2019
14 av 14 2022-01-22 10:19