Skip to content

Instantly share code, notes, and snippets.

@nmvuong92
Forked from abhilash1in/user-data.sh
Created September 3, 2023 05:30
Show Gist options
  • Save nmvuong92/d24534cd8ba636ac546f790ae4600fff to your computer and use it in GitHub Desktop.
Save nmvuong92/d24534cd8ba636ac546f790ae4600fff to your computer and use it in GitHub Desktop.
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment