Packages and Repositories

  • Alpine Linux的软件包是经过数字签名的tar.gz存档,包含程序,配置文件和依赖关系元数据。它们具有扩展名.apk,通常称为“a-packs”。
  • 包存储在一个或多个存储库中。存储库只是一个包含* .apk文件集合的目录。该目录必须包含一个名为APKINDEX.tar.gz的特殊索引文件,以将其视为存储库。
  • 该APK程序可以从多个仓库安装软件包。要检查的存储库列表存储在/etc/apk/repositories中,每行一个存储库。如果从USB(/media/sda1)或CD-ROM(/media/cdrom)启动,则您的存储库文件可能如下所示:
Contents of /etc/apk/repositories
/media/sda1/apks/
  • 除了本地存储库之外,apk实用程序还使用busybox wget来使用http:,https:或ftp: protocols 来获取包。以下是有效的存储库文件:
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
  • 注意: alpine-mirrors的git 仓库有一个mirrors.yaml中包含一个公共仓库的列表,Accepted protocols vary.

Repository pinning

  • You can specify additional "tagged" repositories in /etc/apk/repositories:
  • 可在/etc/apk/repostories下指定附加“已标记”的仓库
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
  • After which you can "pin" dependencies to these tags using:之后,您可以使用以下命令“锁定”这些标记的依赖关系:
apk add stableapp newapp@edge bleedingapp@testing
  • Apk现在默认只使用未标记的存储库,但是向特定包添加标记:
    • 将更喜欢具有该标记的存储库用于命名包,即使该包的更高版本在另一个存储库中可用
    • 允许从标记的存储库中提取标记包的依赖关系(尽管它更喜欢使用未标记的存储库来满足依赖关系)

Commandline repository options

  • 默认情况下,apk实用程序将使用系统存储库进行所有操作。可以通过以下选项覆盖此行为:
--repositories-file REPOFILE        Override the system repositories by specifying a repositories file.
通过指定存储库文件来覆盖系统存储库。
-X|--repository REPO        Specify a supplemental repository that will be used in addition to the system repositories. This option can be provided multiple times.
指定将在系统存储库之外使用的补充存储库。可以多次提供此选项。

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/cache/apk/, /var/lib/apk/ or /etc/apk/cache/.
  • 译:远程仓库的repositories随着软件的升级会更新,可使用update命令获取最新可用的包列表。该命令会从每个远程仓库下载APKINDEX.tar.gz并放到本地缓存。如/var/cache/apk/, /var/lib/apk/ 或 /etc/apk/cache/.
apk update

Add a Package

  • 使用add命令从存储仓库安装软件。同时会安装依赖包。如果同时有多个存储仓库,默认情况下安装最新版软件。
apk add openssh
apk add openssh openntp vim
  • 如果只在配置中启用了主存储库,待安装的apk将不包含其他存储库中的包。要从edge/testing存储库安装软件包而不更改存储库配置文件,可使用以下命令。这将告诉apk包管理器使用该特定存储库。
apk add cherokee --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
  • Note: Be careful when using third-party or the testing repository. Your system can go down.

  • 译:注意:使用第三方测试库时需小心,这可能导致系统宕机。

Add a local Package

  • 如本地有可用包,且网络不可用,可以用以下方法直接安装
apk add --allow-untrusted /path/to/file.apk
  • 如要安装的包有依赖包,可一并列出
apk add --allow-untrusted /var/tig-2.2-r0.apk /var/git-2.11.1-20.apk

Remove a Package

  • 删除包及其依赖
apk del openssh
apk del openssh openntp vim

Upgrade a Running System

  • 升级当前运行系统中的所有包,使用upgrade
apk update
apk upgrade

Search for Packages

  • 使用search命令搜索仓库中可用的包
    • 列出所有可用的包及描述信息:
apk search -v
  • 列出所有包名称中包含acf的包
apk search -v 'acf*' 
  • 列出描述信息中包含NTP的所有包
apk search -v --description 'NTP' 

Information on Packages

  • 列出命令由哪个包提供、依赖关系、以及文件属于哪个包,可自行选择需要显示的元素

    • 如:
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:     触发动作
zlib-1.2.5-r1 has auto-install rule:        自动安装规则
zlib-1.2.5-r1 affects auto-installation of:     自动安装什么
zlib-1.2.5-r1 replaces:         替换的软件
zlib-1.2.5-r1 license:          版本信息

Listing installed packages

  • 列出所有已安装的软件
apk info
  • 列所有已安装软件及描述信息,并按字母排序
apk -vv info|sort

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.

    • 翻译:Alpine Linux需要在启动时可以从本地媒介上拉取软件包。(在网络未连接之前,不会从网络下载软件包。)使用远程仓库有一个问题。如果配置文件改为新版本的仓库源,旧包不在本地媒介上,可能会产生各种问题。
  • 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.
    • 翻译:解决方法是更新本地包缓存,这个缓存可以保存在任何可读写介质上,通常和本地apkovl一致。

Enabling Local Cache 开启本地缓存

  • The cache is enabled by creating a symlink named /etc/apk/cache that points to the cache directory. Note that apk will ignore any cache residing on a tmpfs volume. If you want this for some reason, see section below on tmpfs caches.
    • 翻译:本地缓存会创建一个名为/etc/apk/cache的符号连接。apk在tmpfs存储卷上会跳过所有缓存项。如果你想使用这种存储卷,看下面关于tmpfs缓存的内容。(不,我不并不想看)
  • To enable local cache run:开启本地缓存
setup-apkcache

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,
    • 翻译:如果不小心从缓存目录删除了包信息,你可以使用download命令重新下载
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.
    • 翻译:使用sync命令可以把两步联合为一步执行。这个命令会清除旧包信息并下载新包信息。
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 a /etc/local.d/*.stop file:
    • 翻译:重启时尝试自动验证缓存,可以把以下命令加到/etc/local.d/*.stop文件中:
Contents of /etc/local.d/cache.stop
#!/bin/sh

# 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:
    • 翻译:在某些情况下,你可能想升级系统中所有包,但是想保留一个指定软件为旧版本。在这种情况下,可以添加sticky或者版本依赖。例如,保持asterisk软件在1.6.2版本或更低版本:
apk add asterisk=1.6.0.21-r0
  • 或者
apk add 'asterisk<1.6.1'
  • 然后使用
apk upgrade
  • will upgrade the entire system, keeping the asterisk package at the 1.6.0 or lower level 就可以又升级系统,又保持asterisk在1.6.0版本了
  • To later upgrade to the current version 执行完upgrade,把软件回滚至指定版本:
apk add 'asterisk>1.6.1'

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. If edge is already tagged in your repositories, then try:
    • 翻译:如果您运行的是Alpine Linux稳定版本,并且安装了特定的edge/main、edge/community或测试包,就可能会出现这种情况。解决方案是升级apk工具。如果存储库已经标记edge,可尝试:(翻译的啥东西,自己都看不下去了)
sudo apk add --upgrade apk-tools@edge