Cyrus Stoller home about consulting

Installing node on a mac

In general, I love the simplicity of installing software with Homebrew on a mac. But, when installing programming languages, I’ve found that it often leads to more complications when I later want to use or test a particular version for compatibility with particular libraries. Because Homebrew makes it difficult (and often impossible) to install older versions of a package, I often have difficulty isolating points of failure when troubleshooting.

For example, recently I was trying to quickly install Ember.js on a friend’s computer. To get up and running as quickly as possible, I ran the following commands:

$ brew install node watchman
$ npm install -g ember-cli
$ ember new example
$ cd example
$ ember server

Then, the server was unresponsive unless I uninstalled watchman, which was strange because I had the same version numbers installed on my machine and they were working fine. At this point, I decided to uninstall everything and install everything the same way I had before. And then after installing the same software, everything worked as expected.

Instead of installing node through Homebrew, I installed it with nvm. Here’s how I did it:

$ brew uninstall --force node
# https://github.com/creationix/nvm#manual-install
$ export NVM_DIR="$HOME/.nvm" && (
  git clone https://github.com/creationix/nvm.git "$NVM_DIR"
  cd "$NVM_DIR"
  git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" origin`
) && . "$NVM_DIR/nvm.sh"

Then add the following to your .bashrc or .zshrc like you do with rbenv for ruby.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

Once you have nvm installed, you can install a particular version of node. I ran the following:

$ brew install watchman
$ nvm install --lts
$ npm install -g ember-cli
$ ember new example
$ cd example
$ ember server

Anyway, I hope this will help save you some from unnecessary head scratching when trying to get a dev environment setup. Happy hacking!


My understanding is that you can do something similar when installing node on Linux.

Category Tutorial