Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install node js and npm on Ubuntu/Mac using nvm
# Install node and npm via nvm -
# Run this script like - bash
# Prevent source
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && echo -e "\e[91m This script is being sourced, will exit now \e[39m" && return
# Script will auto terminate on errors
set -e
# Define versions
echo -e "\e[96m Install node version manager v$INSTALL_NVM_VER \e[39m"
# Removed if already installed
rm -rf ~/.nvm
# Install nvm
curl -o-$INSTALL_NVM_VER/ | bash
# Make nvm command available to terminal
source ~/.nvm/
#echo "List all node version available (optional step)"
#nvm ls-remote
echo -e "\e[96m Now install node js v$INSTALL_NODE_VER, change the version number if you want \e[39m"
nvm install $INSTALL_NODE_VER
echo -e "\e[96m Make this version system default \e[39m"
nvm alias default v$INSTALL_NODE_VER
nvm use default
#echo -e "\e[96m Update npm to latest version, if this stuck then terminate (CTRL+C) the execution \e[39m"
#npm install -g npm
echo -e "\e[96m Check for node, npm and nvm version \e[39m"
node --version
npm --version
nvm --version
echo -e "\e[96m Print binary paths \e[39m"
which npm
which node
echo -e "\e[96m List installed node versions \e[39m"
nvm ls
echo -e "\e[92m Please Logout and Login back to take changes effect \e[39m"
# Tested on Travis-CI, Ubuntu, CentOS, Mac OS

How to update nvm itself ?

cd ~/.nvm

Wants to try something else ?

💡 Quick install - Run this script in terminal

wget -qO- | bash
# OR
curl -o- | bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment