I’d like to use the distribution Node.js packages (or the chris-lea ppa for more recent releases) but install NPM to my home directory.
This may seem picky, but it’s a pretty idiomatic way for polyglot/github-using developers to setup language runtime/library environments under Linux: distro packages for the runtime, 3rd-party libraries in per-user environment (see virtualenv, RVM – RVM will also build Ruby for you if you want). If necessary I will build node locally but it’s a PITA since Node is becoming an incidental development requirement for lots of projects.
NPM will install local packages into your projects already, but I still like to keep the system away from my operating system’s files. Here’s how I suggest compartmentalizing Nodejs packages:
Install Nodejs and NPM via the chris-lea PPA. Then I set up a package root in my homedir to hold the Node "global" packages:
Set NPM to use this directory for its global package installs:
Configure your PATH and MANPATH to see commands in your $NPM_PACKAGES prefix by adding the following to your .zshrc/.bashrc:
Now when you do an
npm install -g, NPM will install the libraries into~/.npm-packages/lib/node_modules, and link executable tools into~/.npm-packages/bin, which is in yourPATH.Just use
npm install -gas you would normally: