Permission issue when npm install -g
Blogs20142014-03-27
Permission issue when npm install -g
Normally we use ’npm install -g’ to install global packages, such as ‘grunt’, ‘bower’, ‘karma’, ‘yo’, ‘generator-*’ etc. By default in Linux they are installed to /usr/local/ dir:
- /usr/local/bin/ for binary
- /usr/local/lib, /usr/local/lib/node_modules/ for sources
These dirs is accessible only by ’root’ by default. So if an account, let’s say ’node’, wants to do the installation, every time it has to ask for password when using ‘sudo’, not very convenient. A solution is to include ‘node’ into ‘root’ group, and extend the dirs permission to 775 to allow ‘root’ group to access and write, like this:
$ sudo usermod -a -G root node
$ sudo chmod 775 bin lib lib/node_modules
The about steps only need one time setup; after that, user ’node’ can use ’npm install -g’ to install any packages withou ‘sudo’.
$ npm install -g yo generator-wordpress
$ npm install -g generator-ember
$ npm install -g generator-backbone
It is reasonable if set a specific account to manage npm packages installation instead of ‘root’.