How to switch your Node Js versions

choose the best tool to manger cli versions



If you are develope Node Js apps , you may have a same situation with me. Yes, I want to test my application under the different node versions or I want to try the newest version of node. I want try the `node —harmony`.

Solutions

  • N made by TJ Holowaychuk ,it’s a cool tool to manager the node versions , but it’s a little painful . Sometimes it may break the npm link.
  • Nvm is a similar tool as N , but it’s more complex to install it.


Another Choice

If you are using Mac as your dev machine, you must have heard brew before or use it everyday.If you haven't hear about it , you may have to try it. That will change you life.

Brew also have a command to switch formula versions.

You can use `brew install node ` to install the latest stable node .

Use `brew versions node ` to checkout all stable versions of node.

For example when you want install 0.10.31 version of node , you can run

git checkout 103b7e8 /usr/local/Library/Formula/node.rb

in you your terminal.

(ps: you need run this command under `/usr/local/Cellar` this folder.)

The most import things i want to say is how to install the latest node, not the latest stable node.

For example :

You can run `brew install —devel node —with-0.11.13` this command to install the unstable nodejs version 0.11.13

If you can not link the special version of nodejs , you can try to remove the npm files

rm -rf /usr/local/lib/node_modules/npm

and then try to force link the nodejs use the script below.

brew link —overwrite —dry-run node

If you have multiple nodejs versions installed on your laptop, you can use

brew switch node 0.10.31

switch to the node 0.10.31 and brew will also switch the npm version for you. That’s is the best thing i like brew versions.

Conclusion


There is lots of ways can help get what you want, you may want to choose what is the best way for you .

I choose brew versions because i like brew very much. It’s very simple to use it.

Email me when xeodou publishes or recommends stories