Using local Node binaries

npm allows you to add binaries in the system paths by using the -g option. The installation typically looks like this:

sudo npm -g install coffee-script

However this means you need to: (a) be able to access root, or any other permission level to install global binaries; (b) run the same binaries as anybody else on your system.

A simple way to alleviate the problem is to install the npm packages you need from your home directory, which requires no specific priviledges, and add the proper directory to your path.

The first step is to modify your login shell so that it adds ~/node_modules/.bin to your path; for example using bash, add the following in your ~/.profile:

PATH="$HOME/node_modules/.bin:$PATH"

Now, whenever you install a package from your home directory, its binaries will show up in your path, and you will be able to execute them directly.

cd
npm install coffee-script
coffee -v
which coffee

As a system administrator this also means the only npm application you'll need to install is npm itself; users (esp. developers) can install in their private space all the applications they need.

posted: 2012-10-28 14:40

Written on October 28, 2012