在Alpine Linux上安装旧版本的软件包

总结

最近我开始使用Alpine Linux作为Docker的基础操作系统,但经常会遇到找不到特定版本或旧版本的软件包(或无法安装软件包)的问题。

所以,我稍微研究了一下,为了备忘起见,我会记下笔记。

指定版本

直译的话,是这样的,似乎可以指定。这是我最先找到的文章。

    • linux – How to install a specific package version in Alpine? – Super User

 

    How to install a specific package version in Alpine and Docker? | Today I learned

可是,我尝试了一下却无法安装旧版本的软件包,和我想的感觉不一样。

bash-4.3# apk add --update 'postgresql<9.3' --no-cache
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  postgresql-9.5.4-r0:
    breaks: world[postgresql<9.3]
bash-4.3# apk add --update postgresql=9.3 --no-cache
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  postgresql-9.5.4-r0:
    breaks: world[postgresql=9.3]

请下载并安装APK文件。

我接下来找到的方法是,

    Index of /alpine/

从互联网上下载APK文件。

    installation – How to install .apk on Alpine Linux like .deb in Debian using dpkg – Super User

我已经尝试了一种直接安装的方法。

首先,

寻找PostgreSQL 9.3版本…找到了。

使用wget进行下载。

bash-4.3# cd /tmp/
bash-4.3# wget http://dl-3.alpinelinux.org/alpine/v3.0/main/x86_64/postgresql-9.3.11-r0.apk
Connecting to dl-3.alpinelinux.org (74.117.189.115:80)
postgresql-9.3.11-r0 100% |********************************************************************************************************************************************************************************************|  5001k  0:00:00 ETA
bash-4.3#

安装

bash-4.3# apk add --allow-untrusted postgresql-9.3.11-r0.apk --no-cache
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
(1/6) Installing db (5.3.28-r0)
(2/6) Installing libsasl (2.1.26-r7)
(3/6) Installing libldap (2.4.44-r1)
(4/6) Installing libpq (9.5.4-r0)
(5/6) Installing postgresql-client (9.5.4-r0)
(6/6) Installing postgresql (9.3.11-r0)
Executing busybox-1.24.2-r11.trigger
OK: 52 MiB in 37 packages
bash-4.3#

我确定了。

bash-4.3# su postgres
/tmp $ postgres --version
postgres (PostgreSQL) 9.3.11
/tmp $

成功地安装了PostgreSQL 9.3。

编辑 /etc/apk/repositories。

不必直接下载,只需修改存储库就可以了。真丢脸。

bash-4.3# cat /etc/apk/repositories
# http://dl-cdn.alpinelinux.org/alpine/v3.4/main
# http://dl-cdn.alpinelinux.org/alpine/v3.4/community
http://dl-cdn.alpinelinux.org/alpine/v2.7/main
bash-4.3# apk search --update postgresql
fetch http://dl-cdn.alpinelinux.org/alpine/v2.7/main/x86_64/APKINDEX.tar.gz
collectd-postgresql-5.4.1-r1
postgresql-doc-9.3.10-r0
postgresql-contrib-9.3.10-r0
postgresql-client-9.3.10-r0
freeradius3-postgresql-3.0.10-r0
lua-dbi-postgresql-0.5-r3
freeradius-postgresql-2.2.9-r0
qt-postgresql-4.8.5-r2
acf-postgresql-0.7.0-r0
postgresql-dev-9.3.10-r0
postgresql-9.3.10-r0
bash-4.3#