Alpine Linux, unlike mainstream/traditional Linux distributions, is based on BusyBox, a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - musl. There currently is no musl based binary published in the nodejs official builds but they do publish a musl based binary in the nodejs unofficial builds which they use in the node:alpine docker image. The node:alpine docker image is a potential alternative to nvm for using node on alpine linux.
For now you can override the nvm_get_arch
function to return x64-musl
on x64 Alpine Distributions. Currently the Node project only has unofficial builds for x64-musl
. Sorry no ARM-musl
/x86-musl
,etc
builds for now. The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Official Alpine-compatible binaries.
For more info about unofficial builds visit: https://unofficial-builds.nodejs.org/
If installing nvm on Alpine Linux is still what you want or need to do, you should be able to achieve this by running one of the following from your Alpine Linux shell:
Pre-compiled binaries for musl based architectures are unofficially available for most node versions after node v8.16.0
cd && touch .profile
apk add --no-cache libstdc++ coreutils curl bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
echo "export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release" >> .profile
echo "nvm_get_arch() { nvm_echo \"x64-musl\"; }" >> .profile
source .profile
libstdc++
- is the only package that is necessary to run node/npm once it is installed.bash
- is required to install nvm... BusyBox'ssh
has some issues withchmod
ing the nvm-exec file, but bash can be removed again after install if you want to slim your image.coreutils
/curl
- is required to for nvm because BusyBox is not 100% POSIX compliant. Mainlyls
not accepting a-q
argument andwget
not having the progress bar option.
Since there are no io.js builds available for musl you can also disable all io.js versions from showing up in nvm ls-remote by also running:
echo "export NVM_IOJS_ORG_MIRROR=https://example.com" >> .profile
There is a -s
flag for nvm install
which requests nvm download Node source and compile it locally. This does not use anything unofficial but it is much slower and more cpu intensive to install and build each version of node.
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
Similar to the pre-compiled binaries
libstdc++
- is the only package that is necessary to run node/npm once it is installed.
Got from nvm-sh/nvm#1102 (comment)
Left it here as a gist to find it easier in the future, also, maybe someone else will find it useful