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

use*_*483 99 gruntjs

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

我按照这里的说明进行操作,然后创建了一个包含以下文件的项目文件夹.当我尝试通过在终端输入"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
Run Code Online (Sandbox Code Playgroud)

小智 491

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

npm install -g grunt-cli 
Run Code Online (Sandbox Code Playgroud)

http://gruntjs.com/getting-started上看到它

  • 在小牛队工作. (15认同)
  • 也在linux上,(Ubuntu/Elementary OS) (8认同)
  • 如果没有`sudo`,应该工作得很好(并且可能更好). (4认同)
  • 如果你需要`sudo`,权限是错误的,你将在每次安装时遇到更深的麻烦.总是确保`npm`可以在没有'sudo`的情况下运行. (3认同)
  • 除非在安装`npm`本身时设置了适当的文件夹权限,否则需要@MatthewShanley`sudo`. (2认同)

nsc*_*nni 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/所述,但终端重启可能是要求获得新路径.

  • 看起来像这里http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/但是使用`/ usr/local/share/npm/bin`而不是你在问题中的`/ usr/local/bin/grunt` (2认同)

Moh*_*ngh 12

对于窗户

npm install -g grunt-cli

npm install load-grunt-tasks

然后跑

grunt


Bue*_*eno 6

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


Mon*_*0se 6

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

我在我的项目所在的目录中运行命令"npm install -g grunt-cli"命令.

我再次尝试从我的主目录(即'cd~')并像以前一样安装,除了现在我可以运行grunt命令并且它被识别.


YJ.*_*ang 5

关键是找到安装 grunt 的正确路径。我通过 npm 安装了 grunt,但我的 grunt 路径是/Users/${whoyouare}/.npm-global/lib/node_modules/grunt/bin/grunt. 所以在我添加/Users/${whoyouare}/.npm-global/lib/node_modules/grunt/bin~/.bash_profile,and 之后source ~/.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/