2

I have these four lines at the start of my ec2 user data script to install nvm and Node.js. This never seems to succeed.

touch ~/.bashrc
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install 16

The nvm installer cannot find the .bashrc and conks out:

Cloud-init v. 22.2.2 running 'modules:final' at 2025年1月24日 07:28:19 +0000. Up 14.32 seconds.
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
100 16555 100 16555 0 0 54955 0 --:--:-- --:--:-- --:--:-- 55000
=> Downloading nvm as script to '/.nvm'
=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zprofile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
 OR
=> Append the following lines to the correct file yourself:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
/var/lib/cloud/instance/scripts/part-001: line 6: nvm: command not found

Not sure what I'm doing wrong. Any ideas?

Mureinik
316k54 gold badges404 silver badges406 bronze badges
asked Jan 24, 2025 at 8:28
1
  • What shell does it use? You can find this out by running echo $SHELL. Commented Jan 24, 2025 at 10:51

1 Answer 1

2

This seems like a bug in nvm. I was able to reproduce the error on a local Ubuntu container, and then I spun up a new container, replaced nvm 0.39.7 with the latest 0.40.1, and it worked just fine:

touch ~/.bashrc
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrc
nvm install 16
answered Jan 24, 2025 at 11:02
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.