从终端运行时找不到命令

我刚接触 Grunt,正在我的 Mac OSX Lion 上尝试配置 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
124579 次浏览

I'm guessing you used Brew to install Node, so the guide here might be helpful http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/.

You need to ensure that the npm/bin is in your path as it describes export PATH="/usr/local/share/npm/bin:$PATH". This is the location that npm will install the bin stubs for the installed packages.


The nano version will also work as described here http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/ but a restart of Terminal may be required to have the new path picked up.

My fix for this on Mountain Lion was: -

npm install -g grunt-cli

Saw it on http://gruntjs.com/getting-started

I have been hunting around trying to solve this one for a while and none of the suggested updates to bash seemed to be working. What I discovered was that some point my npm root was modified such that it was pointing to a Users/USER_NAME/.node/node_modules while the actual installation of npm was living at /usr/local/lib/node_modules. You can check this by running npm root and npm root -g (for the global installation). To correct the path you can call npm config set prefix /usr/local.

For windows

npm install -g grunt-cli

npm install load-grunt-tasks

Then run

grunt

Also on OS X (El Capitan), been having this same issue all morning.

I was running the command "npm install -g grunt-cli" command from within a directory where my project was.

I tried again from my home directory (i.e. 'cd ~') and it installed as before, except now I can run the grunt command and it is recognised.

the key point is finding the right path where your grunt was installed. I installed grunt through npm, but my grunt path was /Users/${whoyouare}/.npm-global/lib/node_modules/grunt/bin/grunt. So after I added /Users/${whoyouare}/.npm-global/lib/node_modules/grunt/bin to ~/.bash_profile,and source ~/.bash_profile, It worked.

So the steps are as followings:

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

You can refer http://www.hongkiat.com/blog/grunt-command-not-found/