Alpine Package Keeper: Difference between revisions

From Alpine Linux
(→‎Packages and Repositories: updated repositories to better reflect current usage)
Line 72: Line 72:
<pre>
<pre>
/media/sda1/apks
/media/sda1/apks
http://dl-3.alpinelinux.org/alpine/v1.10/packages/main
http://dl-3.alpinelinux.org/alpine/v2.1/main
https://dl-3.alpinelinux.org/alpine/v1.10/packages/extra
https://dl-3.alpinelinux.org/alpine/v2.1/main
ftp://ftp.alpinelinux.org/edge/packages/main
ftp://dl-3.alpinelinux.org/alpine/v2.1/main
</pre>
</pre>



Revision as of 18:56, 2 March 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
Note: Currently there are no public https or ftp repositories. The protocols are available for local repositories

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/v1.10/packages/main/APKINDEX.tar.gz
fetch http://dl-3.alpinelinux.org/alpine/v1.10/packages/testing/APKINDEX.tar.gz
alpine 1.10.1 [/media/sda1/apks]
main v1.10.1-34-g977ff46 [http://dl-3.alpinelinux.org/alpine/v1.10/packages/main]
testing v1.10.0-32-gbf6b6cb [http://dl-3.alpinelinux.org/alpine/v1.10/packages/testing]
Tip: If using remote repositories, it is a good idea to do an update just before doing an add or upgrade command. That way you know you are using the latest software available

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

Note: Remember that when you reboot your machine, the remote repository will not be available until after networking is started. This means packages newer than your local boot media will likely not be installed after a reboot. To make an "upgrade" persist over a reboot, use a local cache.

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.
Tip: The info command is also useful to determine which package a file belongs to. For example:

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

  1. Create a cache directory on the device you store your lbu backups (typically, /dev/sda1.)

    mkdir /media/sda1/cache

  2. Create a symlink to this directory from /etc/apk/cache.

    ln -s /media/sda1/cache /etc/apk/cache

  3. Run an lbu commit to save the change (/etc/apk/cache is in /etc and is automatically backed up.)

    lbu commit

  4. 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
}
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.

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'