安装期间出现 EACESS 错误

安装期间出现 EACESS 错误

在程序执行期间我收到以下消息:

>> Local Npm module "grunt-cli" not found.

Grunt 已在系统中

lrwxrwxrwx 1 root root     39 Sep 13 20:29 /usr/bin/grunt -> ../lib/node_modules/grunt-cli/bin/grunt*

然后我要安装 grunt本地使用时npm install -g grunt-cli,我收到 EACCES 错误:

$ npm install -g grunt-cli
npm ERR! Linux 3.19.0-28-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "grunt-cli"
npm ERR! node v0.12.7
npm ERR! npm  v2.11.3
npm ERR! path /usr/bin/grunt
npm ERR! code EACCES
npm ERR! errno -13

npm ERR! Error: EACCES, unlink '/usr/bin/grunt'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES, unlink '/usr/bin/grunt'] errno: -13, code: 'EACCES', path: '/usr/bin/grunt' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! error rolling back Error: EACCES, unlink '/usr/bin/grunt'
npm ERR! error rolling back     at Error (native)
npm ERR! error rolling back  { [Error: EACCES, unlink '/usr/bin/grunt'] errno: -13, code: 'EACCES', path: '/usr/bin/grunt' }

npm ERR! Please include the following file with any support request:
npm ERR!     /home/skydog/npm-debug.log

我该怎么做才能npm install -g grunt-cli避免出现 EACESS 错误?

答案1

man npm

   global mode:
          npm    installs    packages   into   the   install   prefix   at
          prefix/lib/node_modules and bins are installed in prefix/bin.

   local mode:
          npm installs packages into the current project directory,  which
          defaults   to   the  current  working  directory.  Packages  are
          installed  to  ./node_modules,  and  bins   are   installed   to
          ./node_modules/.bin.

   Local mode is the default. Use --global or -g on any command to operate
   in global mode instead.

因此,当您使用该-g标志时,您是npm在全局模式下使用的。如果您想使用本地模式,请不要使用该-g标志。

相关内容