I am trying to update Nodejs to the latest version with nvm in the user-data section on AWS ec2 ubuntu server. But somehow it doesn’t update Nodejs to the latest version. Everything works fine via the normal command window.
This is the first codes I tried
#!/bin/bash
#!/bin/bash
yes | sudo apt update
yes | sudo apt upgrade
yes | sudo apt install nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc
nvm install --lts
This is the second code I tried.
#!/bin/bash
yes | sudo apt update
yes | sudo apt upgrade
# Node.js
yes | sudo apt install nodejs
# NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install --lts
When I run other codes of nvm, I get “Command ‘nvm’ not found, but there are 14 similar ones.” gives the warning. But if I do all the codes with normal cmd window it works fine.