Skip to content

Instantly share code, notes, and snippets.

@mmmeff
Forked from ankurk91/install-node-js.sh
Last active April 4, 2017 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmmeff/91705e028ee1158553222adfcf088ba1 to your computer and use it in GitHub Desktop.
Save mmmeff/91705e028ee1158553222adfcf088ba1 to your computer and use it in GitHub Desktop.
Install node js and npm on Ubuntu/Mac using nvm
#!/bin/bash
# Install node and npm via nvm - https://github.com/creationix/nvm
# Run this script like - bash script-name.sh
# 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
INSTALL_NODE_VER=7
INSTALL_NVM_VER=0.33.1
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- https://raw.githubusercontent.com/creationix/nvm/v$INSTALL_NVM_VER/install.sh | bash
# Make nvm command available to terminal
source ~/.nvm/nvm.sh
#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
./install.sh

Wants to try something else ?

💡 Quick install - Run this script in terminal

wget -qO- https://gist.githubusercontent.com/mmmeff/91705e028ee1158553222adfcf088ba1/raw/install-node-js.sh | bash
# OR
curl -o- https://gist.githubusercontent.com/mmmeff/91705e028ee1158553222adfcf088ba1/raw/install-node-js.sh | bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment