Created
April 24, 2018 17:06
-
-
Save abhilash1in/638d928036c4a89421339f3ec2384129 to your computer and use it in GitHub Desktop.
Install nvm and NodeJS using AWS EC2 user data script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Thank you so much! This works for me in Ubuntu 22.04 through EC2 User Data
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work on ec2 ubuntu 20.
Lines
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
return error:
Cannot create /home/ubuntu/.bashrc: Permission denied