Setting up Node projects

Permission denied for npm install --global

This is because npm tries to install to a /usr path which you can't write to. To solve this, you can either change the default directory for global packages or use nvm to take care of installing globally.

If you know you want to run on the most updated version of node, you should just use nvm, which is incompatible with the steps to change your default npm directory below.

To change the default directory, do something like

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

Double check that you do have it setup correctly:

 npm config get prefix

Now npm install --global will install the packages to ~/.npm-global.

You will also want to add ~/.npm-global to your path so that you can run commands installed there without specifying the full path. (eg: if you want the convenience of running bower install <package> instead of ~/.npm-global/bin/bower install <package>). One way to do this is to add it to your bashrc:

echo 'PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc

Now any new bash consoles that you start will have that path convenience.

Using NVM to get the most updated version of node

NVM allows you to install and run different versions of node (and to manage and install their "global packages" separately).

First download the git repo

git clone

Now hook up your shell to use nvm

source ~/nvm/

To automatically run this every time you start a bash shell, add it to your bashrc:

echo 'source ~/nvm/' >> ~/.bashrc

You can now do a nvm ls-remote to see what versions of node are available. Let's install v6.6

nvm install v6.6

You can run nvm use v6.6 to use the new node. To set that as default, set up an nvm alias:

nvm alias default v6.6

This will also solve any permission problems involved with installing with npm install --global will work without needing to specify a prefix.