Skip to content

Instantly share code, notes, and snippets.

@jhnsnc
Created October 2, 2017 20:26
Show Gist options
  • Save jhnsnc/ca2a02f16be0a4ff90d5548f7019c839 to your computer and use it in GitHub Desktop.
Save jhnsnc/ca2a02f16be0a4ff90d5548f7019c839 to your computer and use it in GitHub Desktop.
Snippet to install NVM and set it up with a stable version of Node/NPM
#-------------------------------------------------------------------------------
# Install NVM
#-------------------------------------------------------------------------------
echo -e "Installing nvm, our Node version manager..." true
NVM_DIR="$HOME/.nvm"
if [[ -e "$NVM_DIR" ]]; then
echo -e "Already installed. Moving on..."
else
# install Node Version Manager
git clone https://github.com/creationix/nvm.git "$NVM_DIR" && cd "$NVM_DIR" && git checkout `git describe --abbrev=0 --tags`
echo -e "Complete!"
fi
echo -e "Checking NVM version"
nvm --version
#-------------------------------------------------------------------------------
# Install Node/NPM via NVM
#-------------------------------------------------------------------------------
echo -e "Installing correct Node version and updated NPM..." true
NODE_VERSION="stable" # using nvm's language...
# load nvm command in the script
# will do this and more in the bash_profile for the users
source ~/.nvm/nvm.sh
# Install and use version using NVM
nvm install "$NODE_VERSION"
# Ensure we have the most recent version of npm
npm install npm -g
echo -e "Checking installed Node version"
node -v
echo -e "Checking NPM version"
nvm -v
echo -e "Complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment