Node Version Manager

From Logic Wiki
Jump to: navigation, search


Node Version Manager

You can use a node version manager module (like n, nvm) to install multiple versions of node on your machine and switch seamlessly between them.

Start by installing npm with this command:

curl -L https://npmjs.com/install.sh | sh

With npm installed, install the n package globally:

npm install -g n

With n installed, go ahead and install a few versions of node with the commands:

n 4.4.7 n 6.3.1

Now, you can choose the version of node you want by running the command below and using the arrow keys to select and enter to pick the version 6.3.1:

n

Test your node installation

Check that version 6.3.1 of node is installed with this command:

   node --version

Check that version 3.10.3 of npm is installed with this command:

   npm --version

Install nvm with Homebrew

brew update
brew install nvm
mkdir ~/.nvm
nano ~/.bash_profile

In your .bash_profile file (you may be using an other file, according to your shell), add the following :

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

Back to your shell, activate nvm and check it (if you have other shells opened and you want to keep them, do the same) :

source ~/.bash_profile
echo $NVM_DIR

Now, you can install node :

nvm install 0.12

From now on, you’re using the v0.12.x of node on this shell, you can install your global dependencies such as grunt-cli (they will be tied up to this version of node).

You may want to install other versions, just do :

nvm install 0.10
nvm install iojs
...

You’ll have to npm install -g your global dependencies for each version.

Switch of node version with nvm use 0.10 (more infos here).

To have a node activated by default (not to have to nvm use on each new shell), run this (stable being the id of the version):

nvm alias default stable

Now, you can run multiple versions of node on your computer.