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