我已經做到了這一點:https://stackoverflow.com/a/21712034不能NPM安裝-g沒有sudo改變前綴
現在我的NPM的配置如下:
npm config get prefix
/home/ranu/npm
但是當我運行npm install -g grunt-cli
,我得到:
npm ERR! Error: EACCES, mkdir '/usr/lib/node_modules/grunt-cli'
npm ERR! { [Error: EACCES, mkdir '/usr/lib/node_modules/grunt-cli']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/lib/node_modules/grunt-cli',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/lib/node_modules/grunt-cli',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.11.0-26-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /home/ranu
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! path /usr/lib/node_modules/grunt-cli
npm ERR! fstream_path /usr/lib/node_modules/grunt-cli
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/lib/node_modules/grunt-cli'
npm ERR! fstream_stack /usr/lib/node_modules/npm/node_modules/fstream/lib/dir- writer.js:36:23
npm ERR! fstream_stack /usr/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ranu/npm-debug.log
npm ERR! not ok code 0
如果前綴設置爲/ home/ranu/npm,爲什麼要將其安裝在/ usr/lib/node_modules /上?
UPDATE: 我可以把它做它用下面的命令工作:
npm install --prefix="/home/ranu/npm" -g grunt-cli
有什麼辦法讓它作爲默認?
有由NPM使用2'prefix'es,[每一個局部和整體安裝(HTTPS: //www.npmjs.org/doc/files/npm-folders.html)。由於您在全局安裝,因此它將使用全局前綴 - 「npm config -g get prefix」。另請注意[在NPM中一般建議使用'sudo'](https://github.com/npm/npm#permissions-when-using-npm-to-install-other-stuff)。 – 2014-09-02 17:05:30
可能重複[如何安裝grunt-cli而不會出錯?](http://stackoverflow.com/questions/20555605/how-can-i-install-the-grunt-cli-without-getting-errors ) – 2014-09-02 17:05:57
@JonathanLonowski npm config -g get前綴也是/ home/elranu/npm – elranu 2014-09-02 17:16:25