grunt:从终端运行时找不到命令
Posted
技术标签:
【中文标题】grunt:从终端运行时找不到命令【英文标题】:grunt: command not found when running from terminal 【发布时间】:2013-05-27 23:05:20 【问题描述】:我是 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
【问题讨论】:
从终端运行此命令并将输出添加到您的问题中:which grunt 嗨,Paul,我输入了命令,但没有收到任何输出。 "command not found" after installation的可能重复 ***.com/questions/10667381/… 的欺骗 - 那里的答案很好。 【参考方案1】:我猜你是用 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 存根的位置。
nano 版本也可以按照此处http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/ 的说明工作,但可能需要重新启动终端才能拾取新路径。
【讨论】:
我可以使用 sudo nano /etc/paths 添加这个吗? 这里看起来像 architectryan.com/2012/10/02/…,但使用/usr/local/share/npm/bin
而不是您在问题中的 /usr/local/bin/grunt
我使用 sudo nano /etc/paths 添加了路径,但我仍然没有 grunt 命令 /usr/local/share/npm/bin
如何进入终端中的那个文件夹?
我设法使用 finder 取消隐藏文件夹。我的 npm 文件夹位于 /Users/myusername 下。【参考方案2】:
我在 Mountain Lion 上的解决方法是:-
npm install -g grunt-cli
在http://gruntjs.com/getting-started看到它
【讨论】:
同样在 linux 上,(Ubuntu / Elementary OS) 没有sudo
应该可以正常工作(并且可能更好)。
@MatthewShanley sudo
是必需的,除非在安装 npm
本身时设置了适当的文件夹权限。
如果你需要sudo
,权限是错误的,每次安装都会给自己带来更深的麻烦。始终确保npm
可以在没有sudo
的情况下运行。
与 El Capitain 合作!【参考方案3】:
我一直在寻找解决这个问题的方法,但建议的 bash 更新似乎都没有工作。我发现,我的 npm 根目录在某个时间点被修改,使其指向 Users/USER_NAME/.node/node_modules
,而 npm 的实际安装位于 /usr/local/lib/node_modules
。您可以通过运行npm root
和npm root -g
(用于全局安装)来检查这一点。要更正路径,您可以致电npm config set prefix /usr/local
。
【讨论】:
我无法使用您提供的解决方案同步两条路径【参考方案4】:对于窗户
npm install -g grunt-cli
npm install load-grunt-tasks
然后运行
grunt
【讨论】:
根本没有帮助我 我运行的是 Windows 10,只需要运行 'npm install -g grunt-cli'【参考方案5】:同样在 OS X (El Capitan) 上,整个上午都遇到同样的问题。
我在我的项目所在的目录中运行“npm install -g grunt-cli”命令。
我从我的主目录(即 'cd ~')再次尝试并像以前一样安装它,除了现在我可以运行 grunt 命令并且它被识别。
【讨论】:
【参考方案6】:关键是找到安装 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
和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/
【讨论】:
很好的答案,为我工作(Win7 x64)。这是我放在 .bash_profile 中的内容:export PATH=$PATH:/Users/<username>/AppData/Roaming/npm/node_modules/grunt-cli/bin/grunt
还要检查~/.npm-packages/lib/node_modules/grunt-cli/bin/grunt
(OS X High Sierra)以上是关于grunt:从终端运行时找不到命令的主要内容,如果未能解决你的问题,请参考以下文章