Install nvm / node on AMZ Linux 2 EC2 Instance with userData script

Viewed 29

I'm trying to install nvm / node on an AMZ Linux 2 EC2 Instance using the following userData script:

#!/bin/bash
curl https://raw.githubusercontent.com/creationix/nvm/v0.39.1/install.sh | bash
. ~/.nvm/nvm.sh
nvm install 16.17.0
nvm use 16.17.0

However, when I SSH into the Instance, neither nvm nor node are installed. If I run the commands manually while SSH'd into the Instance, they work fine.

Anyone have any thoughts on why the installs don't work in the userData script? Thanks for any thoughts!

1 Answers

Although I still haven't figure out why the userData Script above doesn't work (it used to, so I'm not sure what changed), I was able to install Node using the following as userData, so I thought I'd share.

#!/usr/bin/env bash
yum update -y
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum install -y nodejs git

I'd still be interested to know why the first script no longer works, if anyone has any idea.

Cheers!

Rob

Related