每个linux发行版本都有自己的软件包管理工具,如centos的
yum
,ubuntu的apt
,而alpine linux则是apk
。这里apk不是android的软件包哈。
apk源配置
apk源配置文件位于/etc/apk/repositories
, 国内镜像源推荐的是阿里云,也可以是清华的,两个速度都不错。
- 阿里云apk远
https://mirrors.aliyun.com/alpine/v3.14/main
- 清华apk源
https://mirror.tuna.tsinghua.edu.cn/alpine/v3.14/main
apk命令
输入 apk --help
可以看到详细的命令帮助。
edge:~# apk --help
apk-tools 2.12.6, compiled for x86_64.
usage: apk [<OPTIONS>...] COMMAND [<ARGUMENTS>...]
Package installation and removal:
add Add packages to WORLD and commit changes
del Remove packages from WORLD and commit changes
System maintenance:
fix Fix, reinstall or upgrade packages without modifying WORLD
update Update repository indexes
upgrade Install upgrades available from repositories
cache Manage the local package cache
Querying package information:
info Give detailed information about packages or repositories
list List packages matching a pattern or other criteria
dot Render dependencies as graphviz graphs
policy Show repository policy for packages
search Search for packages by name or description
Repository maintenance:
index Create repository index file from packages
fetch Download packages from global repositories to a local directory
manifest Show checksums of package contents
verify Verify package integrity and signature
Miscellaneous:
audit Audit system for changes
stats Show statistics about repositories and installations
version Compare package versions or perform tests on version strings
This apk has coffee making abilities.
For more information: man 8 apk
edge:~#
apk更新
apk update
用于更新本地软件索引。update只是从源下载软件索引,本地软件索引一般存储在:
/var/cache/apk/
/var/lib/apk/
/etc/apk/cache/
edge:~# apk update
fetch http://mirrors.ustc.edu.cn/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
v3.14.0-160-g18a21f8aa5 [http://mirrors.ustc.edu.cn/alpine/v3.14/main]
OK: 4785 distinct packages available
edge:~#
软件搜索
apk search
可用于搜索软件,如搜索nginx:
edge:~# apk search nginx
nginx-1.20.1-r3
nginx-mod-http-geoip2-1.20.1-r3
nginx-mod-http-dav-ext-1.20.1-r3
nginx-mod-http-cookie-flag-1.20.1-r3
nginx-mod-mail-1.20.1-r3
nginx-mod-http-lua-upstream-1.20.1-r3
nginx-mod-stream-js-1.20.1-r3
nginx-mod-http-upload-progress-1.20.1-r3
nginx-mod-http-lua-1.20.1-r3
nginx-mod-http-untar-1.20.1-r3
nginx-mod-rtmp-1.20.1-r3
nginx-openrc-1.20.1-r3
nginx-mod-http-log-zmq-1.20.1-r3
nginx-mod-http-echo-1.20.1-r3
nginx-mod-http-set-misc-1.20.1-r3
nginx-mod-http-image-filter-1.20.1-r3
nginx-mod-http-nchan-1.20.1-r3
nginx-debug-1.20.1-r3
nginx-mod-stream-geoip2-1.20.1-r3
nginx-mod-http-shibboleth-1.20.1-r3
nginx-mod-http-cache-purge-1.20.1-r3
nginx-mod-http-fancyindex-1.20.1-r3
nginx-mod-http-redis2-1.20.1-r3
nginx-mod-http-zip-1.20.1-r3
nginx-mod-http-geoip-1.20.1-r3
nginx-mod-http-accounting-1.20.1-r3
nginx-mod-http-headers-more-1.20.1-r3
nginx-mod-http-upstream-jdomain-1.20.1-r3
nginx-mod-stream-1.20.1-r3
nginx-mod-http-vts-1.20.1-r3
nginx-mod-http-xslt-filter-1.20.1-r3
nginx-vim-1.20.1-r3
nginx-mod-devel-kit-1.20.1-r3
nginx-mod-http-perl-1.20.1-r3
nginx-mod-http-brotli-1.20.1-r3
nginx-mod-http-js-1.20.1-r3
nginx-mod-http-array-var-1.20.1-r3
nginx-mod-http-encrypted-session-1.20.1-r3
nginx-mod-http-upstream-fair-1.20.1-r3
nginx-mod-http-naxsi-1.20.1-r3
nginx-mod-http-vod-1.20.1-r3
nginx-doc-1.20.1-r3
nginx-mod-stream-geoip-1.20.1-r3
命令 | 说明 |
---|---|
apk search | 查找所有可用软件包 |
apk search -v | 查找所有可用软件包及其描述内容 |
apk search -v ‘nginx*’ | 通过软件包名称查找软件包 |
apk search -v -d ‘nginx’ | 通过描述文件查找特定的软件包 |
安装软件
apk add
命令用于安装软件,并自动安装必须的依赖包,也可以从第三方仓库添加软件包。如添加nginx软件apk add nginx
:
edge:~# apk add nginx
(1/4) Installing pcre (8.44-r0)
(2/4) Installing nginx (1.20.1-r3)
Executing nginx-1.20.1-r3.pre-install
Executing nginx-1.20.1-r3.post-install
(3/4) Installing nginx-openrc (1.20.1-r3)
(4/4) Installing nginx-vim (1.20.1-r3)
Executing busybox-1.33.1-r3.trigger
OK: 1017 MiB in 174 packages
安装指定版本的软件则需要:
apk add nginx=1.9.0
apk add 'nginx<1.9.0'
apk add 'nginx>1.9.0'
显示软件包的信息
apk info
命令用于显示软件包的信息。
命令 | 说明 |
---|---|
apk info | 列出所有已安装的软件包 |
apk info -a nginx | 显示完整的软件包信息 |
apk info --who-owns /sbin/lbu | 显示指定文件属于的包 |
软件升级
apk upgrade
用于升级所有已安装的软件。
apk update
apk upgrade
也可指定某个软件,如nginx:
apk add --upgrade nginx
卸载软件
apk del
用于卸载软件。
apk del nginx