咕unt声:找不到命令 [英] grunt: command not found

查看:88
本文介绍了咕unt声:找不到命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

npm知道grunt已在全球安装,为什么找不到它?

npm knows that grunt is installed globally, so why isn't it found?

$ npm install -g grunt
... installs ...
$ npm list -g | grep grunt
│   ├─┬ gruntfile-editor@0.2.0
│   ├─┬ gruntfile-editor@0.2.0
├─┬ grunt@0.4.5
│ ├─┬ grunt-legacy-log@0.1.1
│ ├── grunt-legacy-util@0.2.0
$ grunt
-bash: grunt: command not found

我认为是因为它被放置在不在我的PATH上的某个位置.

I assume because it's put it somewhere that is not on my PATH.

为什么默认情况下npm不只是将其放在我的PATH上,例如/usr/local/bin?

Why doesn't npm just put it somewhere that is on my PATH by default, like /usr/local/bin?

更新:奇怪的是,即使我执行npm install grunt在本地运行它,我仍然遇到相同的grunt: command not found错误.我究竟做错了什么?我的存储库中有一个Gruntfile.js.

UPDATE: Weirdly, I get the same grunt: command not found error even after I do npm install grunt to run it locally. What am I doing wrong? There is a Gruntfile.js in my repo.

推荐答案

"grunt"软件包是任务运行程序本身,而"grunt-cli"软件包是包含grunt可执行文件的命令行界面.您可以确保将其安装到正确的路径.

The package "grunt" is the task runner itself whereas the "grunt-cli" package is the command line interface that includes the grunt executable. You can make sure that it is installed to the correct path.

如果您执行npm install grunt-cli,它仍然无法正常工作,因为它将安装在相应目录中的node_modules中,该目录很可能不在您的路径中.但是,当您从全局安装的CLI工具中使用grunt时,它将寻找该项目以及Gruntfile.js

If you do npm install grunt-cli it still would not work because this would be installed to node_modules in the corresponding directory which is most likely not on your path. However, when you use grunt from the globally installed CLI tool it will look for an installation of grunt that is local to that project as well as the Gruntfile.js

你要做的是

  1. 全局安装grunt-cli:

$ npm install grunt-cli -g

$ npm install grunt-cli -g

在您的依赖项中本地安装grunt(可以选择将依赖项保存到package.json中):

install grunt local in your dependencies (optionally save the dependency to your package.json):

$ npm install grunt --save

$ npm install grunt --save

这篇关于咕unt声:找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆