Skip to content

Instantly share code, notes, and snippets.

@nolybom
Forked from ankurk91/install-node-js.sh
Created March 28, 2018 15:14
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 nolybom/4641c7977c3a4c4e74e72d520a17dd88 to your computer and use it in GitHub Desktop.
Save nolybom/4641c7977c3a4c4e74e72d520a17dd88 to your computer and use it in GitHub Desktop.
Install node-js, npm and yarn 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
# Define versions
INSTALL_NODE_VER=8
INSTALL_NVM_VER=0.33.8
echo "==> Make sure bash profile exists and writable"
touch ~/.bash_profile
echo "==> Installing node version manager v$INSTALL_NVM_VER"
# 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 "==> Installing node js v$INSTALL_NODE_VER"
nvm install $INSTALL_NODE_VER
echo "==> Make this version system default"
nvm alias default $INSTALL_NODE_VER
nvm use default
#echo -e "==> Update npm to latest version, if this stuck then terminate (CTRL+C) the execution"
#npm install -g npm
echo "==> Installing Yarn package manager"
rm -rf ~/.yarn
curl -o- -L https://yarnpkg.com/install.sh | bash
echo "==> Checking for versions"
nvm --version
node --version
npm --version
echo "==> Print binary paths"
which npm
which node
echo "==> List installed node versions"
nvm ls
nvm cache clear
echo "==> Please Logout and Login back to take changes effect"
# Tested on Ubuntu, CentOS, MacOS

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/ankurk91/8f107ef490f40f74a1cf/raw/install-node-js.sh | bash
# OR
curl -o- https://gist.githubusercontent.com/ankurk91/8f107ef490f40f74a1cf/raw/install-node-js.sh | bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment