Why does Alpine apk report "unsatisfiable constraints" when installing an older version of Node.js?
I'm trying to install an older version of Node.js (4.4.4) on Alpine. Here are my commands:
apk update
apk add nodejs-lts=4.4.4-r0
When I execute, I get an error (running as root because I'm using the Alpine:3.4 Docker image):
/ # apk update
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
v3.4.6-64-gd029d25 [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
v3.4.6-33-g38ef2d2 [http://dl-cdn.alpinelinux.org/alpine/v3.4/community]
OK: 5977 distinct packages available
/ # apk add nodejs-lts=4.4.4-r0
ERROR: unsatisfiable constraints:
nodejs-lts-4.6.0-r0:
breaks: world[nodejs-lts=4.4.4-r0]
How do I install a specific, older version of a package in apk
?
Solution 1:
That is correct. Unfortunately, 4.4.4 is not available.
You should avoid being explicit on package versions unless controlling your own package mirror and package builds, rather allow the package system to handle it for the Alpine release in use.
For Alpine 3.4, only 4.6.0 is available. Search Alpine 3.4 x86_64 Packages Online for nodejs-lts
If you are so inclined, here's the source for the package to change in order to build a specific version of choice.
Review the package source
Alpine has a wiki page: Creating an Alpine package.
Note that 'nodejs-lts' package name is deprecated.
provides="nodejs-lts=$pkgver" # for backward compatibility
replaces="nodejs-current nodejs-lts" # nodejs-lts for backward compatibility
Solution 2:
Unfortunately, Alpine-Linux Package Management drops older packages when there are newer versions available. This makes it hard to use Alpine Linux with docker since you want a reproducible image with exact versions.
See this article for the entire rundown. The two solutions that are offered: Create you own mirror and host the specific version of the packages you wish to keep having access to (probably not worth the effort) or use a different base image such as Ubuntu who's package management system doesn't drop older versions of packages (as intuitively expected from any modern day package management system).
And, I suppose you could just update your docker file to use the latest available version of those packages. However, it'll only be a matter of time before you run into this same situation again. It's just not scalable if you are building for a production system.
Solution 3:
You can use a specific version from previous alpine release using the following, with example of alia-lib-dev
which is set to 1.1.7-r0 in alpine edge but here forced to be 1.1.6-r0 from alpine 3.8:
apk add --no-cache --update-cache --repository http://nl.alpinelinux.org/alpine/v3.8/main alsa-lib-dev=1.1.6-r0
Solution 4:
Just uncomment the entry containing community in /etc/apk/repositories
. Then run apk update
and apk add <PKG>
.