Skip to content

Instantly share code, notes, and snippets.

@fabriziogiordano
Last active August 29, 2015 14:27
Show Gist options
  • Save fabriziogiordano/790fbba01c05c583bb95 to your computer and use it in GitHub Desktop.
Save fabriziogiordano/790fbba01c05c583bb95 to your computer and use it in GitHub Desktop.
Using Homebrew to manage Node.js and io.js installs on OSX

Using Homebrew to manage Node.js and io.js installs on OSX

Having both Node.js and io.js installed with NVM was giving me a load of problems, mainly with npm. So I uninstalled NVM and manage Node.js and io.js with homebrew.
Heres how.

Install Node.js and io.js

$ brew install node
$ brew install iojs

Note the io.js install information:

This formula is keg-only.
iojs conflicts with node (which is currently more established)

So we have both Node.js and io.js installed, however iojs is only linked to the command iojs in our PATH.

So, we can unlink node: brew unlink node, and link iojs: brew link --force iojs this will link io.js to node and other commands.

Now when we need to use Node.js rather than io.js, we can just

$ brew unlink iojs && brew link node

To go back to io.js

$ brew unlink node && brew link --force iojs

And we can alias these (add to .bashrc / .zshrc)

alias usenode='brew unlink iojs && brew link node && echo Updating NPM && npm install -g npm@latest && echo Using Node.js'
alias useio='brew unlink node && brew link --force iojs && echo Updating NPM && npm install -g npm@latest && echo Using io.js'

Now we can $ usenode when we want to use Node.js, and $ useio when we want to use io.js

Twitter

Using Switch

$ brew switch node 0.12.2_1
Cleaning /usr/local/Cellar/node/0.10.36
Cleaning /usr/local/Cellar/node/0.12.2_1
6 links created for /usr/local/Cellar/node/0.12.2_1
$ node -v
v0.12.2

and switch back again!

$ brew switch node 0.10.36
Cleaning /usr/local/Cellar/node/0.10.36
Cleaning /usr/local/Cellar/node/0.12.2_1
5 links created for /usr/local/Cellar/node/0.10.36
$ node -v
v0.10.36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment