Node.js - Configuring $NODE_PATH with NVM

Solution 1:

Adding following to .bashrc or .zshrc helps

export NODE_PATH=$NODE_PATH:`npm root -g`

I am not expert whether that is good.

source as pointed out by Pensierinmusica

Solution 2:

NVM will set the path for node and npm once you run

nvm use <node_version>

However, that is just for the current shell and any new shells will not have a version of node an npm selected until your run the previous command unless you set a default version

nvm alias default <node_version>

voila! You have a working version of npm and node in any new shell you open.

To change the default simply run it again with the new version of node you want to use. e.g.

nvm alias default v5.4.0

Solution 3:

I figured a way to make this work.

In your ~/.bash_rc file or ~/.zsh_rc add this line:

export NODE_PATH=`which node`

Open new shell or run this source ~/.bash_rc to pick up the changes