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
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
apk update
apk upgrade
Search for Packages
apk search -v
apk search -v 'acf*'
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.web
- 翻译: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"vim
- 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