apk软件管理——玩转alpine linux

每个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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

名栩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值