Installing NVM, Node.js, and NPM on Yosemite

There are several ways to install Node.js on Yosemite:

  1. install the package from the Node.js site,
  2. install via brew install node,
  3. and install via nvm, the Node Version Manager.

Naturally, I’ve decided to go with the least straightforward approach, which is installing via nvm. After spending too much time on the subject, it appears that Homebrew is a perfectly acceptable way to install Node, although that hasn’t always been the case. Manual installation is also a fine way to install it. However, I chose to nvm primarily for its versioning capabilities; that is, it works much like rvm/rbenv in that it can download and manage multiple versions of Node. Now, I’m not sure that I’ll ever need to keep track of multiple versions of Node, but it’s nice to have the option.

Prerequisites:

brew install wget
brew install git

Install NVM:

git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`

in order to have it available upon login, add the following to .bash_profile:

source ~/.nvm/nvm.sh

NVM commands:

to see what’s currently installed:

nvm ls

to see what versions of Node are available for install:

nvm ls-remote

Install Node:

once you’ve looked at which versions are available,

nvm install x.x.x (where x.x.x is the version number)

alternately, simply

nvm install stable | unstable depending on your preference.

to set as default:

nvm use stable

to confirm:
nvm ls
node -v

Install NPM:

just kidding, NPM is installed automatically with Node.
npm -v

References:

Installation and use of NVM: NVM
StackOverflow discussion on homebrew vs manual installation: Installing Node.js – pros/cons of using Brew vs manually managing?

This entry was posted in JavaScript, local.config, NodeJS. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *