node.js 节点包 ( Grunt ) 已安装但不可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10667381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node package ( Grunt ) installed but not available
提问by AJP
I'm trying to build a github jquery-ui libraryusing grunt, but after running npm installI still can't run the command according to the readme file. It just gives No command 'grunt' found:
我试图建立一个GitHub的jQuery的UI库使用grunt,但运行后npm install我还是根据无法运行该命令自述文件。它只是给出No command 'grunt' found:
james@ubuntu:~/Documents/projects/ad2/lib/jquery-ui$ grunt build
No command 'grunt' found, did you mean:
Command 'grun' from package 'grun' (universe)
grunt: command not found
james@ubuntu:~/Documents/projects/ad2/lib/jquery-ui$ npm ls
[email protected] /home/james/Documents/projects/ad2/lib/jquery-ui
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└── [email protected]
I'm confused, what am I missing please?
我很困惑,请问我错过了什么?
回答by Tom P
The command line tools are not included with the latest version of Grunt (0.4 at time of writing) instead you need to install them separately.
命令行工具未包含在最新版本的 Grunt(在撰写本文时为 0.4)中,您需要单独安装它们。
This is a good idea because it means you can have different versions of Grunt running on different projects but still use the nice concise gruntcommand to run them.
这是一个好主意,因为这意味着您可以在不同的项目上运行不同版本的 Grunt,但仍然使用简洁的grunt命令来运行它们。
So first install the grunt cli tools globally:
所以首先全局安装 grunt cli 工具:
npm install -g grunt-cli
(or possibly sudo npm install -g grunt-cli).
(或可能sudo npm install -g grunt-cli)。
You can establish that's working by typing grunt --version
您可以通过键入来确定它是否有效 grunt --version
Now you can install the current version of Grunt local to your project. So from your project's location...
现在您可以将当前版本的 Grunt 本地安装到您的项目中。所以从你的项目位置...
npm install grunt --save-dev
The save-devswitch isn't strictly necessary but is a good idea because it will mark grunt in its package.json devDependencies section as a development only module.
这个save-dev开关并不是绝对必要的,但它是一个好主意,因为它会将 grunt 在它的 package.json devDependencies 部分标记为一个仅用于开发的模块。
回答by Sam Figueroa
Add /usr/local/share/npm/bin/to your $PATH
添加/usr/local/share/npm/bin/到您的$PATH
回答by rayfranco
If you did have installed Grunt package by running npm install -g gruntand it still say's No command 'grunt' foundor grunt: command not found, a quick and dirty way to get this working is linking node binaries to your $PATH manually.
如果您确实通过运行安装了 Grunt 包npm install -g grunt,但它仍然显示为No command 'grunt' foundor grunt: command not found,则一种快速而肮脏的方法是手动将节点二进制文件链接到您的 $PATH 。
On MacOSX/Linux you can add this line to your ~/.bash_profileor ~/.bashrcfile.
在 MacOSX/Linux 上,您可以将此行添加到您的~/.bash_profile或~/.bashrc文件中。
PATH=$PATH:/usr/local/Cellar/node/HEAD/bin # Add NPM binaries
You probably should replace /usr/local/Cellar/node/HEAD/binby the path where your node binaries could be found.
您可能应该替换/usr/local/Cellar/node/HEAD/bin为可以找到节点二进制文件的路径。
If this is quick and dirtyto me, it's because everything should work without doing this, but for an unknown reason, a link seem broken. As nobody on IRC could tell me why this happened, I found my own way to make it (grunt) work.
如果这对我来说又快又脏,那是因为如果不这样做,一切都应该可以工作,但由于未知原因,链接似乎已损坏。由于 IRC 上没有人能告诉我为什么会发生这种情况,我找到了自己的方法来让它(咕噜声)工作。
PS: This should help you make grunt works, this answer is not jquery-ui related.
PS:这应该可以帮助你使 grunt 工作,这个答案与 jquery-ui 无关。
Update 02/2013: You should take a look at @tom-p's answerwhich explains better what is going on. Tom gives us the real solution instead of hacking your bashrc file : both should work, but you should try installing grunt-clifirst.
02/2013 更新:您应该看看@tom-p 的回答,它更好地解释了正在发生的事情。汤姆给了我们真正的解决方案,而不是黑客你的.bashrc文件:既要工作,但你应该尝试安装grunt-cli第一。
回答by Edgard Leal
In my case, i need modify the file /usr/local/bin/grunt in line 1 ( don't make this ):
就我而言,我需要修改第 1 行中的文件 /usr/local/bin/grunt (不要这样做):
#!/usr/bin/env node //remove this line
#!/usr/bin/env nodejs // and put this line to run with nodejs
Edited:
编辑:
To avoid problems, I created a link with the name of "node" because many other programs still use "node" command.
为了避免出现问题,我创建了一个名为“node”的链接,因为许多其他程序仍然使用“node”命令。
sudo ln -s /usr/bin/nodejs /usr/sbin/node
回答by Marvin
On WIN7 I had to manually add the path to the npm folder (which contains the elusive 'grunt' file) to the Windows PATH environmental variable.
In my case that was C:\Users\mhaagsma\AppData\Roaming\npm
在 WIN7 上,我必须手动将 npm 文件夹(其中包含难以捉摸的“grunt”文件)的路径添加到 Windows PATH 环境变量中。
就我而言,那是C:\Users\mhaagsma\AppData\Roaming\npm
回答by tomajar
There is one more way to run grunt on windows, without adding anything globally. This is a case when you don't have to do anything with %PATH%
还有一种在 Windows 上运行 grunt 的方法,无需全局添加任何内容。这是您不必对 %PATH% 做任何事情的情况
if you have grunt and grunt-cli installed (without -g switch). Either by:
如果您安装了 grunt 和 grunt-cli(没有 -g 开关)。或者通过:
npm install grunt-cli
npm install [email protected]
Or by having that in your packages.json file like:
或者在你的packages.json文件中使用它,例如:
"devDependencies": {
"grunt-cli": "^1.2.0",
"grunt": "^0.4.5",
You can call grunt from your local installation by:
您可以通过以下方式从本地安装调用 grunt:
node node_modules\grunt-cli\bin\grunt --version
This is a solution for those who for some reasons don't want to or can't play with PATH, or have something else messing it all the time, for instance on a build agent.
对于那些由于某些原因不想或不能使用 PATH 或一直有其他东西弄乱它的人来说,这是一个解决方案,例如在构建代理上。
Edit: Added versions as the grunt-cli works with grunt > 0.3
编辑:添加版本,因为 grunt-cli 适用于 grunt > 0.3
回答by Adonis K. Kakoulidis
The right way to install grunt is by running this command:
安装 grunt 的正确方法是运行以下命令:
npm install grunt -g
(Prepend "sudo" to the command above if you get a EACCESS error message)
(如果您收到 EACCESS 错误消息,请在上面的命令前加上“sudo”)
-g will make npm install the package globally, so you will be able to use it whenever you want in your current machine.
-g 将使 npm 全局安装软件包,因此您可以随时在当前机器上使用它。
回答by Theva
Hello I had this problem on mac, and what I did was
你好,我在 mac 上遇到了这个问题,我所做的是
installed globally and prefix with global path
全局安装并带有全局路径前缀
sudo npm install grunt -g --prefix=/usr/local
now
$ which grunt
现在
$ which grunt
should out put
/usr/local/bin/grunt
应该出
/usr/local/bin/grunt
Cheers
干杯
回答by lowerkey
Sometimes you have to npm install package_name -gfor it to work.
有时你必须npm install package_name -g让它工作。
回答by Israel Morales
Other solution is to remove the ubuntu bundler in my case i used:
其他解决方案是在我使用的情况下删除 ubuntu bundler:
sudo apt-get remove ruby-bundler
That worked for me.
那对我有用。

