Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install nvm and NodeJS using AWS EC2 user data script
#!/bin/bash
apt-get -y update
cat > /tmp/subscript.sh << EOF
# START UBUNTU USERSPACE
echo "Setting up NodeJS Environment"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.9/install.sh | bash
echo 'export NVM_DIR="/home/ubuntu/.nvm"' >> /home/ubuntu/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> /home/ubuntu/.bashrc
# Dot source the files to ensure that variables are available within the current shell
. /home/ubuntu/.nvm/nvm.sh
. /home/ubuntu/.profile
. /home/ubuntu/.bashrc
# Install NVM, NPM, Node.JS & Grunt
nvm install --lts
nvm ls
EOF
chown ubuntu:ubuntu /tmp/subscript.sh && chmod a+x /tmp/subscript.sh
sleep 1; su - ubuntu -c "/tmp/subscript.sh"
@abhilashshettigar

This comment has been minimized.

Copy link

@abhilashshettigar abhilashshettigar commented Feb 20, 2020

thanks a lot saved much time

@nycjay01

This comment has been minimized.

Copy link

@nycjay01 nycjay01 commented Sep 8, 2020

This does not work via ec2 user data

@AdieOlami

This comment has been minimized.

Copy link

@AdieOlami AdieOlami commented Oct 4, 2020

This does not work via ec2 user data

I believe it is because you are running CentosOS and not Ubuntu.

@joseafilho

This comment has been minimized.

Copy link

@joseafilho joseafilho commented Jan 20, 2021

Very top! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment