grunt:从终端运行时找不到命令

时间:2013-06-01 04:04:35

标签: gruntjs

我是Grunt的新手。我正在尝试在我的Mac OSX Lion上配置Grunt。

我按照说明here,然后创建了一个包含以下文件的项目文件夹。当我尝试通过在终端输入“grunt”来运行时,我得到command not found。我还修改了我的路径sudo nano /etc/paths,希望添加路径可以使任务运行器工作,但它仍然无法正常工作。有人可以协助吗?

---paths

/usr/bin 
/bin
/usr/sbin
/sbin
/usr/local/bin
/usr/local/bin/grunt


--- files
node modules
Gruntfile.js
package.json

6 个答案:

答案 0 :(得分:487)

我对Mountain Lion的解决方法是: -

npm install -g grunt-cli 

http://gruntjs.com/getting-started

上看到它

答案 1 :(得分:43)

我猜您使用Brew来安装Node,因此这里的指南可能会有所帮助http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/

您需要确保npm / bin位于路径中,因为它描述了export PATH="/usr/local/share/npm/bin:$PATH"。这是npm将为已安装的软件包安装bin存根的位置。


纳米版本也将如此处所述http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/工作,但可能需要重新启动终端以获取新路径。

答案 2 :(得分:12)

对于Windows

npm install -g grunt-cli

npm install load-grunt-tasks

然后运行

grunt

答案 3 :(得分:6)

我一直在寻找解决这个问题一段时间,并且没有任何建议的bash更新似乎有效。我发现的是,某些点我的npm根被修改为指向Users/USER_NAME/.node/node_modules而实际安装的npm生活在/usr/local/lib/node_modules。您可以通过运行npm rootnpm root -g(针对全局安装)来检查此问题。要更正路径,您可以拨打npm config set prefix /usr/local

答案 4 :(得分:6)

同样在OS X(El Capitan)上,整个上午都有同样的问题。

我在我的项目所在的目录中运行命令“npm install -g grunt-cli”。

我再次从我的主目录(即'cd~')尝试并按原样安装,除了现在我可以运行grunt命令并识别它。

答案 5 :(得分:4)

关键是找到安装grunt的正确路径。 我通过npm安装了grunt,但是我的grunt路径是/Users/${whoyouare}/.npm-global/lib/node_modules/grunt/bin/grunt。因此,在我将/Users/${whoyouare}/.npm-global/lib/node_modules/grunt/bin添加到~/.bash_profilesource ~/.bash_profile之后,它发挥了作用。

所以步骤如下:

1. find the path where your grunt was installed(when you installed grunt, it told you. if you don't remember, you can install it one more time)

2. vi ~/.bash_profile

3. export PATH=$PATH:/your/path/where/grunt/was/installed

4. source ~/.bash_profile

你可以参考 http://www.hongkiat.com/blog/grunt-command-not-found/