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:add Add PACKAGEs to 'world' and install (or upgrade) them, while ensuring that all dependencies are metdel Remove PACKAGEs from 'world' and uninstall themfix Repair package or upgrade it without modifying main dependenciesupdate Update repository indexes from all remote repositoriesinfo Give detailed information about PACKAGEs or repositoriessearch Search package by PATTERNs or by indexed dependenciesupgrade Upgrade currently installed packages to match repositoriescache Download missing PACKAGEs to cache and/or delete unneeded files from cacheversion Compare package versions (in installed database vs. available) or do tests on literal version stringsindex Create repository index file from FILEsfetch Download PACKAGEs from global repositories to a local directoryaudit Audit the directories for changesverify Verify package integrity and signaturedot Generate graphviz graphspolicy Show repository policy for packagesstats Show statistics about repositories and installationsmanifest Show checksums of package contentsGlobal options:-h, --help Show generic help or applet specific help-p, --root DIR Install packages to DIR-X, --repository REPO Use packages from REPO-q, --quiet Print less information-v, --verbose Print more information (can be doubled)-i, --interactive Ask confirmation for certain operations-V, --version Print program version and exit-f, --force Enable selected --force-* (deprecated)--force-binary-stdout Continue even if binary data is to be output--force-broken-world Continue even if 'world' cannot be satisfied--force-non-repository Continue even if packages may be lost on reboot--force-old-apk Continue even if packages use unsupported features--force-overwrite Overwrite files in other packages--force-refresh Do not use cached files (local or from proxy)-U, --update-cache Update the repository cache--progress Show a progress bar--progress-fd FD Write progress to fd--no-progress Disable progress bar even for TTYs--purge Delete also modified configuration files (pkg removal) and uninstalled packages from cache (cache clean)--allow-untrusted Install packages with untrusted signature or no signature--wait TIME Wait for TIME seconds to get an exclusive repository lock before failing--keys-dir KEYSDIR Override directory of trusted keys--repositories-file REPOFILE Override repositories file--no-network Do not use network (cache is still used)--no-cache Do not use any local cache path--cache-dir CACHEDIR Override cache directory--arch ARCH Use architecture with --root--print-arch Print 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 #顯示指定文件屬于的包
參考鏈接:https://blog.csdn.net/liupeifeng3514/article/details/80418887
總結
以上是生活随笔為你收集整理的Alpine Linux 中的 apk 命令讲解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: wsl centos7: Failed
- 下一篇: WSL端口映射到win