Alpine Linux 中的 apk 命令讲解

枕上从妨一夜睡,灯前读尽十年诗。这篇文章主要讲述Alpine Linux 中的 apk 命令讲解相关的知识,希望能为你提供帮助。
Alpine Linux是一个面向安全应用的轻量级Linux发行版。它采用了musl libc和busybox以减小系统的体积和运行时资源消耗,同时还提供了自己的包管理工具apk。
官方帮助文档
alpine 提供了非常好用的apk软件包管理工具,通过apk –help命令查看完整的包管理命令。

# apkapk-tools 2.8.2, compiled for x86_64.usage: apk COMMAND [-h|--help] [-p|--root DIR] [-X|--repository REPO] [-q|--quiet] [-v|--verbose] [-i|--interactive] [-V|--version] [-f|--force] [--force-binary-stdout] [--force-broken-world] [--force-non-repository] [--force-old-apk] [--force-overwrite] [--force-refresh] [-U|--update-cache] [--progress] [--progress-fd FD] [--no-progress] [--purge] [--allow-untrusted] [--wait TIME] [--keys-dir KEYSDIR] [--repositories-file REPOFILE] [--no-network] [--no-cache] [--cache-dir CACHEDIR] [--arch ARCH] [--print-arch] [ARGS]...The following commands are available: addAdd PACKAGEs to \'world\' and install (or upgrade) them, while ensuring that all dependencies are met delRemove PACKAGEs from \'world\' and uninstall them fixRepair package or upgrade it without modifying main dependencies updateUpdate repository indexes from all remote repositories infoGive detailed information about PACKAGEs or repositories searchSearch package by PATTERNs or by indexed dependencies upgradeUpgrade currently installed packages to match repositories cacheDownload missing PACKAGEs to cache and/or delete unneeded files from cache versionCompare package versions (in installed database vs. available) or do tests on literal version strings indexCreate repository index file from FILEs fetchDownload PACKAGEs from global repositories to a local directory auditAudit the directories for changes verifyVerify package integrity and signature dotGenerate graphviz graphs policyShow repository policy for packages statsShow statistics about repositories and installations manifestShow checksums of package contentsGlobal options: -h, --helpShow generic help or applet specific help -p, --root DIRInstall packages to DIR -X, --repository REPOUse packages from REPO -q, --quietPrint less information -v, --verbosePrint more information (can be doubled) -i, --interactiveAsk confirmation for certain operations -V, --versionPrint program version and exit -f, --forceEnable selected --force-* (deprecated) --force-binary-stdoutContinue even if binary data is to be output --force-broken-worldContinue even if \'world\' cannot be satisfied --force-non-repositoryContinue even if packages may be lost on reboot --force-old-apkContinue even if packages use unsupported features --force-overwriteOverwrite files in other packages --force-refreshDo not use cached files (local or from proxy) -U, --update-cacheUpdate the repository cache --progressShow a progress bar --progress-fd FDWrite progress to fd --no-progressDisable progress bar even for TTYs --purgeDelete also modified configuration files (pkg removal) and uninstalled packages from cache (cache clean) --allow-untrustedInstall packages with untrusted signature or no signature --wait TIMEWait for TIME seconds to get an exclusive repository lock before failing --keys-dir KEYSDIROverride directory of trusted keys --repositories-file REPOFILE Override repositories file --no-networkDo not use network (cache is still used) --no-cacheDo not use any local cache path --cache-dir CACHEDIROverride cache directory --arch ARCHUse architecture with --root --print-archPrint default arch and exitThis apk has coffee making abilities.

使用示例
下面列举常用命令:
apk update
update:从远程镜像源中更新本地镜像源索引。
update命令会从各个镜像源列表下载APKINDEX.tar.gz并存储到本地缓存,一般在/var/cache/apk/(Alpine在该目录下)、/var/lib/apk/ 、/etc/apk/cache/下。
apk add
add:安装PACKAGES并自动解决依赖关系。
add命令从仓库中安装最新软件包,并自动安装必须的依赖包,也可以从第三方仓库添加软件包。
$ apk add openssh openntp vim
$ apk add --no-cache mysql-client
$ apk add docker --update-cache --repository http://mirrors.ustc.edu.cn/alpine/v3.4/main/ --allow-untrusted
安装指定版本软件包
$ apk add asterisk=1.6.0.21-r0
$ apk add ‘asterisk< 1.6.1’
$ apk add \'asterisk> 1.6.1
apk del
del:卸载并删除PACKAGES
apk del openssh openntp vim
apk upgrade
upgrade:升级当前已安装的软件包。
upgrade命令升级系统已安装的所有软件包(一般包括内核),当然也可指定仅升级部分软件包(通过-u或–upgrade选择指定)。
$ apk update #更新最新本地镜像源
$ apk upgrade #升级软件
$ apk add --upgrade busybox #指定升级部分软件包
apk search
search:搜索软件包。
search命令搜索可用软件包,-v 参数输出描述内容,支出通配符,-d 或 –description 参数指定通过软件包描述查询。
$ apk search #查找所有可用软件包
$ apk search -v #查找所有可用软件包及其描述内容
$ apk search -v ‘acf*’ #通过软件包名称查找软件包
$ apk search -v -d ‘docker’ #通过描述文件查找特定的软件包
apk info
info:列出PACKAGES或镜像源的详细信息。
info命令用于显示软件包的信息。
$ apk info #列出所有已安装的软件包
$ apk info -a zlib #显示完整的软件包信息
$ apk info --who-owns /sbin/lbu #显示指定文件属于的包
【Alpine Linux 中的 apk 命令讲解】

    推荐阅读