Node.js Grunt安装错误:";应安装-g";

Node.js Grunt安装错误:";应安装-g";,node.js,npm,gruntjs,Node.js,Npm,Gruntjs,我正试图在我的机器上安装Grunt。我读过一些书,也遵循了一些原则,但我无法让它发挥作用 CLI使用以下命令安装ok: sudo npm install -g grunt-cli 当我选择一个本地目录(包含package.json和Gruntfile)和npm install时,我会看到以下消息: npm WARN prefer global grunt-cli@0.1.9 should be installed with -g 为什么会这样?我确实安装了-g-我理解这意味着“全局” 在这之

我正试图在我的机器上安装Grunt。我读过一些书,也遵循了一些原则,但我无法让它发挥作用

CLI使用以下命令安装ok:

sudo npm install -g grunt-cli
当我选择一个本地目录(包含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

当您安装语言环境软件包时,可能需要依赖于软件包请求
grunt cli
。别担心,这个警告并不意味着它损坏了任何东西

grunt:command not found
表示未将grunt二进制文件添加到路径中。加上它,你就会没事了:

要添加的路径应该是终端输出的路径:
/Users/tonyMac/.node/bin


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

您不应该使用
sudo
安装包。
如果使用
sudo
安装node和npm时出现问题。
我知道您使用OSX,所以请相信我,使用brew数据包管理器()安装node,并让它为您处理node和npm

首先删除节点,然后按照说明安装Brew。
然后您只需键入
brew安装节点
,一切都会很顺利。

谢谢oozic!我删除了节点并重新安装了brew(好东西!)。我再次尝试运行grunt,但不幸的是我遇到了一些错误,如:
ERR!错误:EACCES,取消链接
以管理员身份运行命令
。这听起来对吗?我可以提供更多的代码。好吧,你是在为你的机器使用管理员帐户还是有限制的帐户?我有管理权限,这是唯一的用户帐户。可能对某个文件/目录有读/写限制?我不知道您安装的全部历史记录。这有点困难,请尝试
brew doctor
,看看是否有一些错误。至少您可以尝试删除所有node/npm二进制文件,然后从brew重新安装。感谢oozic,我非常感谢这一点,也非常感谢这一点。为什么我们需要删除所有节点/npm二进制文件,我是在安装brew之前删除的?我对
brew doctor
没有任何错误,也更新了brew。我看到的唯一错误是Xcode已经过时(4.5.1),我会更新它,希望它能工作。伙计,我只是想看看格伦特。谢谢你,西蒙-那么这个命令正确吗
export PATH=~/opt/bin:$/Users/tonyMac/.node/bin
不应该有
$
(选择项目文件夹),我运行了它,然后
npm安装
。这将返回
-bash:npm:command not found
。我不明白出了什么问题?您覆盖了完整路径,而不是扩展它。编辑了我的答案,详细介绍了如何扩展path变量。