I'm trying to install node from source on alpine docker.
wget https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz
tar -xvf node-v14.4.0-linux-x64.tar.xz
And once I try to run it:
~/node-v14.4.0-linux-x64/bin # ./node
sh: ./node: not found
Although the file is here, I have the permission and it is executable
~/node-v14.4.0-linux-x64/bin # ls -la
total 70376
drwxr-xr-x 2 root root 4096 Oct 7 11:53 .
drwxr-xr-x 6 1001 1001 4096 Oct 7 11:53 ..
-rwxr-xr-x 1 root root 72052312 Jun 2 14:33 node
lrwxrwxrwx 1 root root 38 Oct 7 11:53 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx 1 root root 38 Oct 7 11:53 npx -> ../lib/node_modules/npm/bin/npx-cli.js
When I do same action on ubuntu it works.
This happens because alpine uses musl
instead of glibc
, and the binaries distributed from node's website are built against glibc
.
Here are a few solutions for your problem, in order of preference (and why):
Use node's official image instead of trying to install it from a alpine base image: that's because there are different dependencies and things to setup before having a working node image (certificates, tls libraries, etc). This is the most recommended.
Installing node via apk
: node is available at alpine's official package manager apk, and you can install it by simply running apk add nodejs
. The only problem here is that the version that's available in the repository is the LTS (12.18.4 as of 2020-10-07).
Installing/building a compability layer for glibc
in alpine: this is not recommended at all, since alpine is built over musl
and running glibc
is not a good practice and can lead to things breaking. Even installing the official libc6-compat
may lead to problems:
Running node using libc6-compat:
$ ./node
Error relocating ./node: gnu_get_libc_version: symbol not found
Error relocating ./node: __register_atfork: symbol not found
Error relocating ./node: __strdup: symbol not found
Error relocating ./node: setcontext: symbol not found
Error relocating ./node: makecontext: symbol not found
Error relocating ./node: backtrace: symbol not found
Error relocating ./node: getcontext: symbol not found
Running node using this answer's suggestion for glibc
:
$ ./node
./node: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
Stick to node's official image (solution 1) and things should work out fine :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With