2

我正在尝试在我的机器上安装 Grunt。我已经阅读了一些教程并遵循了安装文档,但我无法让它工作。

CLI 使用以下命令安装成功:

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,例如:

$ 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
4

2 回答 2

2

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

首先删除节点,然后按照说明安装 Brew。然后你可以输入brew install node,一切都像一个魅力。

于 2013-11-04T22:25:12.807 回答
1

当您安装 locale packagesnpm install时,可能会将包请求grunt-cli作为依赖项。别担心,这个警告并不意味着它破坏了任何东西。

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

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

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

于 2013-11-04T22:17:55.683 回答