Alpine Package Keeper: Difference between revisions
Jrthomerson (talk | contribs) No edit summary |
|||
Line 60: | Line 60: | ||
Software packages for Alpine Linux are digitally signed tar.gz archives containing the programs, configuration files, and dependency metadata. They have the extension "*.apk", and are often called "a-packs" | Software packages for Alpine Linux are digitally signed tar.gz archives containing the programs, configuration files, and dependency metadata. They have the extension "*.apk", and are often called "a-packs" | ||
The packages are stored in one or more ''repositories'' | The packages are stored in one or more ''repositories''. A repository is simply a directory with a collection of *.apk files. The 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 <tt>/etc/apk/repositories</tt>, one repository per line. If you booted from USB stick (<tt>/media/sda1</tt>) or CD-ROM (<tt>/media/cdrom</tt>), your repository file probably looks like this: | The '''apk''' utility can install packages from multiple repositories. The list of repositories to check is stored in <tt>/etc/apk/repositories</tt>, one repository per line. If you booted from USB stick (<tt>/media/sda1</tt>) or CD-ROM (<tt>/media/cdrom</tt>), your repository file probably looks like this: | ||
Line 68: | Line 68: | ||
</pre> | </pre> | ||
In addition to local repositories, the '''apk''' utility uses '''busybox wget''' to fetch packages using ''http:'', ''https:'' or ''ftp:'' protocols. | 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: | ||
<pre> | <pre> |
Revision as of 06:01, 15 June 2011
Alpine Linux Package Management
Because Alpine Linux is designed to run from RAM, package management involves two phases:
- Installing / Upgrading / Deleting packages on a running system
- Restoring a system to a previously configured state (e.g. after reboot), including all previously installed packages and locally modified configuration files. (RAM-Based Installs Only)
apk is the tool used to install, upgrade, or delete software on a running sytem
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 - See the Alpine Local Backup page for the lbu tool.
The apk tool has the following applets:
add | Add new packages to the running system |
del | Delete packages from the running system |
fix | Attempt to repair or upgrade an installed package |
update | Update the index of available packages |
info | Prints information about installed or available packages |
search | Search for packages or descriptions with wildcard patterns |
upgrade | Upgrade the currently installed packages |
cache | Maintenance operations for locally cached package repository |
version | Compare version differences between installed and available packages |
index | create a repository index from a list of packages |
fetch | download (but not install) packages |
audit | List changes to the file system from pristine package install state |
verify | Verify a package signature |
Quickstart Guide
Packages and Repositories
Software packages for Alpine Linux are digitally signed tar.gz archives containing the programs, configuration files, and dependency metadata. They have the extension "*.apk", and are often called "a-packs"
The packages are stored in one or more repositories. A repository is simply a directory with a collection of *.apk files. The 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 USB stick (/media/sda1) or CD-ROM (/media/cdrom), your repository file probably looks like this:
/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:
/media/sda1/apks http://dl-3.alpinelinux.org/alpine/v2.1/main https://dl-3.alpinelinux.org/alpine/v2.1/main ftp://dl-3.alpinelinux.org/alpine/v2.1/main
Update the Package list
Remote repositories change as packages are added and upgraded. To get the latest list of available packages, use the update command. The command downloads the APKINDEX.tar.gz from each repository and stores it in the local cache, typically /var/lib/apk or /etc/apk/cache.
apk update
fetch http://dl-3.alpinelinux.org/alpine/v2.1/main/APKINDEX.tar.gz
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.
apk add openssh apk add openssh openntp vim
Remove a Package
Use del to remove a package (and dependencies that are no longer needed.)
apk del openssh apk del openssh openntp vim
Upgrade a Running System
To upgrade all the packages of a running system, use upgrade
apk update apk upgrade
To upgrade only a few packages, use the add command with the -u parameter:
apk update apk add -u busybox
Search for Packages
The search command searches the repository Index files for installable packages.
Examples:
- To list all packages available, along with their descriptions:
apk search -v
- To list all packages are part of the ACF system:
apk search -v 'acf*'
- To list all packages that list NTP as part of their description:
apk search -v -d 'NTP'
Info on Packages
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 is displayed with the -a command.
Example:
apk info -a zlib
zlib-1.2.5-r1 description: A compression/decompression Library zlib-1.2.5-r1 webpage: http://zlib.net zlib-1.2.5-r1 installed size: 94208 zlib-1.2.5-r1 depends on: libc0.9.32 zlib-1.2.5-r1 is required by: libcrypto1.0-1.0.0-r0 apk-tools-2.0.2-r4 openssh-client-5.4_p1-r2 openssh-5.4_p1-r2 libssl1.0-1.0.0-r0 freeswitch-1.0.6-r6 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:
As shown in the example you can determine
- The description of the package
- The webpage where the application is hosted
- The size the package will require once installed (in bytes)
- What packages are required to use this one (depends)
- What packages require this one to be installed (required by)
- The contents of the package
- Any triggers this package sets. Listed here are directories that are watched; if a change happens to the directory, then the trigger script is run at the end of the apk add/delete. For example, doing a depmod once after installing all packages that add kernel modules.
apk info --who-owns /sbin/lbu
will display/sbin/lbu is owned by alpine-conf-x.x-rx
Additional apk Commands
In progress...
Local Cache
Alpine Linux needs to be able to pull packages from local media on boot. (You can't download packages from the net before you have a network connection.) Using remote repositories presents a problem. If the config files have been modified for a newer version of a package, and the older package is on local media, all sorts of fun can result.
The solution is a local cache of updated packages. This cache can be stored on any r/w media, typically the same location as the apkovl.
To Enable Local Cache
- Create a cache directory on the device you store your lbu backups (typically,
/dev/sda1
.)mkdir /media/sda1/cache
mount -o remount,rw /media/sda1
and then don't forget to runmount -o remount,ro /media/sda1
when you are done with the following commands- Create a symlink to this directory from
/etc/apk/cache
.ln -s /media/sda1/cache /etc/apk/cache
- Run an lbu commit to save the change (
/etc/apk/cache
is in/etc
and is automatically backed up.)lbu commit
- Done. 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 in preference.
So you now have a run-from-RAM distro that can do a yum upgrade or apt-get dist-upgrade
Cache Maintenance
Over time, newer packages will replace older ones; the cache directory will contain all older versions of packages.
Delete Old Packages
To clean out older versions of packages, run the clean command.
apk cache clean
or to see what is deleted
apk -v cache clean
Download Missing Packages
If you accidentally delete packages from the cache directory, you can make sure they are there with the download command,
apk cache download
Delete and Download In One Step
You can combine the two steps into one with the sync command - this cleans out old packages and downloads missing packages.
apk cache -v sync
Automatically Cleaning Cache on Reboot
To automatically attempt to validate your cache on reboot, you can add the above command to the /etc/conf.d/local
script, in the stop
stanza:
local_stop() { # This is a good place to unload any misc. # programs you started above. # verify the local cache on shutdown apk cache -v sync # We should always return 0 return 0 }
Advanced APK Usage
Holding a specific package back
In certain cases, you may want to upgrade a system, but keep a specific package at a back level. It is possible to add "sticky" or versioned dependencies. For instance, to hold the asterisk package to the 1.6.2 level or lower:
apk add asterisk=1.6.0.21-r0
or
apk add 'asterisk<1.6.1'
after which a
apk upgrade
will upgrade the entire system, keeping the asterisk package at the 1.6.0 or lower level
To later upgrade to the current version,
apk add 'asterisk>1.6.1'