Grunt安装错误/ s:“应该用-g安装”

我试图在我的机器上安装Grunt。 我已经阅读了一些教程,并按照安装文档 ,但我不能得到它的工作。

CLI使用以下命令安装好:

sudo npm install -g grunt-cli 

当我select一个本地目录(包含package.json和Gruntfile)和npm install ,我看到以下消息:

 npm WARN prefer global grunt-cli@0.1.9 should be installed with -g 

为什么发生这种情况? 我确实用-g安装 – 意思是“全局的”,我明白了。

在此之后,似乎我不能跑咕噜,例如:

 $ grunt -bash: grunt: command not found $ grunt --version -bash: grunt: command not found 

我怎样才能解决这个问题? 我错过了什么?

这是我的完整日志:

 $ sudo npm install -g grunt-cli Password: npm http GET https://registry.npmjs.org/grunt-cli npm http GET https://registry.npmjs.org/grunt-cli npm http GET https://registry.npmjs.org/grunt-cli npm http GET https://registry.npmjs.org/nopt npm http GET https://registry.npmjs.org/findup-sync npm http GET https://registry.npmjs.org/resolve npm http GET https://registry.npmjs.org/nopt npm http GET https://registry.npmjs.org/findup-sync npm http GET https://registry.npmjs.org/resolve npm http GET https://registry.npmjs.org/nopt npm http GET https://registry.npmjs.org/findup-sync npm http GET https://registry.npmjs.org/resolve npm http GET https://registry.npmjs.org/abbrev npm http GET https://registry.npmjs.org/glob npm http GET https://registry.npmjs.org/lodash npm http GET https://registry.npmjs.org/abbrev npm http GET https://registry.npmjs.org/glob npm http GET https://registry.npmjs.org/lodash npm http GET https://registry.npmjs.org/abbrev npm http GET https://registry.npmjs.org/glob npm http GET https://registry.npmjs.org/lodash npm http GET https://registry.npmjs.org/minimatch npm http GET https://registry.npmjs.org/graceful-fs npm http GET https://registry.npmjs.org/inherits npm http GET https://registry.npmjs.org/minimatch npm http GET https://registry.npmjs.org/graceful-fs npm http GET https://registry.npmjs.org/inherits npm http GET https://registry.npmjs.org/minimatch npm http GET https://registry.npmjs.org/graceful-fs npm http GET https://registry.npmjs.org/inherits npm http GET https://registry.npmjs.org/lru-cache npm http GET https://registry.npmjs.org/sigmund npm http GET https://registry.npmjs.org/lru-cache npm http GET https://registry.npmjs.org/sigmund npm http GET https://registry.npmjs.org/lru-cache npm http GET https://registry.npmjs.org/sigmund /Users/tonyMac/.node/bin/grunt -> /Users/tonyMac/.node/lib/node_modules/grunt-cli/bin/grunt grunt-cli@0.1.10 /Users/tonyMac/.node/lib/node_modules/grunt-cli ├── resolve@0.3.1 ├── nopt@1.0.10 (abbrev@1.0.4) └── findup-sync@0.1.2 (lodash@1.0.1, glob@3.1.21) Tonys-iMac:~ tonyMac$ cd projects/testingGrunt Tonys-iMac:testingGrunt tonyMac$ npm install npm WARN prefer global grunt-cli@0.1.9 should be installed with -g 

你不应该使用sudo来安装软件包。
如果你使用sudo当你安装node和npm的时候出了问题。
我看到你使用OSX,所以请相信我,使用brew数据包pipe理器( http://brew.sh )安装节点,并为你处理node和npm。

先删除节点,然后按照说明安装Brew。 然后你可以inputbrew install node ,一切都像魅力一样。

当您安装您的语言环境软件包npm install ,可能会有一个软件包请求grunt-cli作为依赖项。 不要担心,这个警告并不意味着它破坏了任何东西。

grunt: command not found意味着grunt二进制文件不会被添加到您的path中。 添加它,你会没事的: https : //unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

添加的path应该是你的terminal输出中的一个: /Users/tonyMac/.node/bin

在Bash中: PATH=$PATH:/Users/tonyMac/.node/bin (如果你在命令行中运行它,那么在之前添加export命令)。