How to Install Global Node Modules properly

Running into Permission denied issues when installing Node modules globally?

> node postinstall

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
path.js:1142
          cwd = process.cwd();
                        ^

Lately I had some trouble installing tabris-cli. A colleague told me about the option to install Node modules locally.

With npm-config you can check your current Node configuration:

$ npm config list
; cli configs
scope = ""
user-agent = "npm/4.2.0 node/v7.10.0 darwin x64"

; node bin location = /usr/local/bin/node
; cwd = /Users/node
; HOME = /Users/node
; "npm config ls -l" to show all defaults.

To change to local installation:

$ npm config set prefix=$HOME/node

This will add the following userconfig:

$ npm config list
....
; userconfig /Users/fluffi/.npmrc
prefix = "/Users/fluffi/node"
....

Now we can install tabris-cli globally:

$ npm install -g tabris-cli
....

Add export PATH=$HOME/node/bin:$PATH to your * .profile * .bashrc * .zshrc * ... open a new Terminal and verify your installation:

$ tabris --version
0.3.0

Please note: this is an iOS and Linux solution only.

For more options/alternative solutions please visit Installing global node modules (Linux and Mac) or isaacs/node-and-npm-in-30-seconds.sh.