Stop EACCES errors with npm/node on Ubuntu?

Setup the system environment

$ lsb_release -a 2> /dev/null | grep Desc
Description:    Ubuntu 14.04.1 LTS

$ sudo apt-get install build-essential
$ sudo add-apt-repository ppa:chris-lea/node.js && sudo apt-get update
$ sudo apt-get install nodejs && sudo npm update -g npm
$ sudo npm install -g yo generator-angular && cd /tmp && mkdir b && cd $_

Generate (yeoman)

/tmp/b $ yo angular
[?] Would you like to use Sass (with Compass)? No
[?] Would you like to include Bootstrap? No
[?] Which modules would you like to include? 
 ⬢ angular-animate.js
 ⬢ angular-cookies.js
 ⬡ angular-resource.js
 ⬡ angular-route.js
 ⬢ angular-sanitize.js
 ⬢ angular-touch.js

Errors

npm-debug.log


Is there some trick—short of chowning /usr/lib/node_modules—that will stop these errors from occuring?

Solution

(feel free to use a path other than $HOME/npm)

  1. Remove everything but npm from global node_modules folder (/usr/lib/node_modules)
  2. $ mkdir "$HOME/npm"
  3. $ npm config set prefix "$HOME/npm"
  4. $ printf "NODE_PATH=$NODE_PATH:$HOME/npm/lib/node_modules\nPATH=$PATH:$HOME/npm:$HOME/npm/bin\n" >> ~/.bashrc && source ~/.bashrc