-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Installing on Alpine Linux #1102
Comments
I do think the above is correct. To provide Alpine-compatible binaries, node itself would have to provide them - |
Ah, I see...I thought NVM maintained a separate repo. I'll file a bug with the Node project. Would NVM need any changes to download the correct binary for Alpine and other busybox-based OS's? Just for note - Thanks for the quick response! |
Any changes nvm would need would be minimal - solely grabbing the right OS and architecture strings, based on what node chose. It seems like when |
OK cool, thanks for that - seems like a reasonably easy win then. I have filed nodejs/node#6965. For speed, binaries would be best of course but building from source would be helpful as a fallback. Thanks again! |
Sorry, also just thought...are you interested in adding some info to either a separate doc or the main readme for Alpine/busybox users? How to get NVM working on these is fresh in my memory and I think it'd be useful to note how to get it installed and what the current limitations are (and why) on Alpine/busybox would be useful - it took me an hour or two of reading and trying things so maybe it might save other folks some time which is always nice :-) |
If it's more than a few sentences, I'd love to see a draft first, otherwise a PR to the main readme is great. |
OK cool - i'll draft something over the next day or two and post it here - i'll keep it as short as possible. |
Hi again @ljharb Here's my draft on the above - please let me know what you think and/or whether you want me to PR it in some fashion (add to readme.md or a new doc - i'm thinking new doc might be best as it's probably only interesting to a minority). I won't be offended if you think this is complete rubbish so please let me know your honest thoughts 😼. ###Installing NVM on Alpine Linux 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. This makes binary programs built for such mainstream/traditional incompatible with Alpine Linux, thus we cannot simply There is a If installing NVM on Alpine Linux is still what you want or need to do, you should be able to achieve this by running the following from you Alpine Linux shell:
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries. As a potential alternative, Michael Hart (a Node contributor) has some Docker images for Alpine Linux with Node and optionally, NPM, pre-installed. Cheers |
Thanks, this looks great! I guess this can go as a section in the readme between "Compatibility issues" and "Problems"? |
Great. I'll send a PR as soon as I get a moment. |
Could you help me understand the status of this? I came with this intent of opening a separate issue, but while looking through existing issues first, this one surprised me. I seem to have no trouble installing It did take me a bit to get it working, but because I was not installing the Since this is is for an alpine docker image for a Jenkins agent, I was hoping to skip the need for a system Should a system |
@travi you shouldn't need the "nodejs" package for anything, nor a system node. The prefix error is likely that you have a "prefix" line in |
Ok, thanks. That at least confirms my thought that a system node should be unnecessary. This is a clean docker image with no I'll get this broken into a separate issue. |
I have 3 potential options that enable using nvm on alpine with precompiled binaries in the node unofficial-builds project. https://unofficial-builds.nodejs.org/ <-- these are used in the official node:alpine docker images currently. Option 1I have a branch I can submit for a pull request for just readme updates Installing nvm on Alpine LinuxAlpine 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 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: Using Precompiled Binaries on AlpinePre-compiled binaries for musl based architectures are unofficially available for most node versions after 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
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 Building from Source on AlpineThere is a 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
Option 2I also have another option that detects musl automatically for people in if (ldd $(which echo) | nvm_grep -q musl); then
NVM_ARCH="${NVM_ARCH}-musl"
fi The readme is also updated in this branch similarly to Option 1 but without the override script and info. It would also require some more work to update the version references everywhere before it could be pulled. Option 3I'm also open to making a couple more adjustments to Option 2 that would have nvm automatically backup to the unofficial-build mirror if no normal distribution was found without manually having to set NVM_NODEJS_ORG_MIRROR. Which basically would fully resolve this issue. Let me know if you like any of these options :) Sorry for such a long message, I wanted to include everything I had 👍 |
@bpmccurdy thanks; sorry for the delay. Noting in the docs that Alpine only requires Can you elaborate a bit more on the |
@bpmccurdy thanks. This works perfectly for me, it installs node in the image and allows to change the version from the inside container. for testing purposes. I use zsh, but I think the same should work with bash. RUN apk add --no-cache libstdc++; \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash; \
echo 'source $HOME/.profile;' >> $HOME/.zshrc
RUN { \
echo 'export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release;'; \
echo 'nvm_get_arch() { nvm_echo "x64-musl"; }'; \
} > $HOME/.profile; \
NVM_DIR="$HOME/.nvm"; source $HOME/.nvm/nvm.sh; source $HOME/.profile; \
nvm install 13.8.0 or like so RUN apk add --no-cache libstdc++; \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash; \
echo 'source $HOME/.profile;' >> $HOME/.zshrc; \
echo 'export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release;' >> $HOME/.profile; \
echo 'nvm_get_arch() { nvm_echo "x64-musl"; }' >> $HOME/.profile; \
NVM_DIR="$HOME/.nvm"; source $HOME/.nvm/nvm.sh; source $HOME/.profile; \
nvm install 13.8.0 |
Taking the instructions from above, I have created a little wrapper that you can use without making changes to export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release
NVM_DIR="$HOME/.nvm"
source "$HOME/.nvm/nvm.sh"
nvm_get_arch() { nvm_echo "x64-musl"; }
nvm $@ If you want I guess you can alias this over the original nvm. Not sure if it works though. |
@takase1121 if there's a way to detect |
Well, I found a way to do that quite reliably. I was looking around and found this. It checks output of In order to confirm the reliability of this method, I cloned This is where support for This is the script I used: found=0
total=0
firstfound=""
for commit in $(git rev-list --reverse master)
do
git checkout $commit > /dev/null 2>&1
grep --include="dynlink.c" -rnw '.' -e "musl" > /dev/null
if [ $? -eq 0 ]
then
if [ -z "$firstfound" ]; then firstfound="$commit"; fi
found=$(( found + 1 ))
fi
total=$(( total + 1 ))
done
percentage=$(echo "scale=2; $found / $total * 100" | bc)
echo "$found out of $total commits has it, $percentage% coverage"
echo "First found in $firstfound" However this is only a proof from musl's source code. The distro could change it themselves and that is a problem. I don't have time and resources to conduct tests on multiple machines/VMs. Hopefully somebody else can give a better proof than mine. EDIT: |
I was using @bpmccurdy 's option 1 but with latest docker image update nvm stopped working. There is some strange curl error (416 ). I'm using nvm version 0.39.1 and docker amazeeio/php - 8.0-cli-drupal-22.2.0, amazeeio/php - 7.4-cli-drupal-latest
|
This is pretty much what is needed on the export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release # Set up unofficial builds
export NVM_IOJS_ORG_MIRROR=https://example.com # (Optional) Disable IOJS from appearing on ls-remote
nvm_get_arch() { nvm_echo x64-musl; } # Needed to build the download URL |
why someone can't just fix this issue once and for all? Alpine is everywhere since docker is out, its just a tiny |
@asolopovas nvm isn't going to point to "unofficial builds", they're unofficial. I would be happy to accept a PR that returns the proper |
#3212, some tests are failing, but for it to work NVM_NODEJS_ORG_MIRROR environment varialbe must be equale to "https://unofficial-builds.nodejs.org/download/release", or how would you like me to add the propper value than? |
It’d be fine to use that in tests, but to be clear - what happens when pointing to the default node version list with that arch? |
If understood you correctly, nothing should happen without unless
environment variabl NVM_NODEJS_ORG_MIRROR is set to url with musl build it
will fail trying to get musl build from official source
…On Sun, 1 Oct 2023, 00:43 Jordan Harband, ***@***.***> wrote:
It’d be fine to use that in tests, but to be clear - what happens when
pointing to the default node version list with that arch?
—
Reply to this email directly, view it on GitHub
<#1102 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABUS5IDTWTSXCX6O55PU7S3X5CVBTANCNFSM4CEZFXYA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Then we should have a test for that failure. |
Hi
First off, thanks for NVM - I use it frequently and see it being used everywhere and it's been great. To that end, I'd really like to use NVM on my current project which is basically a CI running via Docker - i'd like to be able to use Alpine Linux as the base image.
I can get NVM to install on Alpine by doing:
Which is great. But then the resulting Node binary won't run and I believe from doing a little reading that this is likely to be because Alpine needs musl rather than GCC built binaries.
I tried using the
-s
flag innvm install
but that tells me it is not usable for Node > 1.I see Alpine and other busybox-based distros gaining a lot of traction as they're so fast, perfect for containerised use - hence my interest.
So my question is...Do you think the above is correct and if so (or if similar), can I offer help in perhaps providing Alpine-compatible binaries? I can perhaps script a compilation of all the existing versions of Node source - though it'd take some time to run - then upload them somewhere e.g. S3.
If the above is of any interest, please let me know as I am keen to help wherever necessary.
Cheers
Neil
The text was updated successfully, but these errors were encountered: