ruby 执行gem时,未知命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10863576/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 05:09:58  来源:igfitidea点击:

While executing gem, unknown command

rubyrubygemsgem

提问by nullnullnull

Whenever I enter a gem command, such as

每当我输入 gem 命令时,例如

gem "tilt"

or

或者

gem "mysql"

I get this error:

我收到此错误:

While executing gem ... <RuntimeError>
Unknown command tilt

When I run gem list, both tilt and mysql show up on the list, so they are installed. In fact, I get this error with every item on the list. What could be causing this?

当我运行时gem list,tilt 和 mysql 都出现在列表中,所以它们被安装了。事实上,我对列表中的每个项目都遇到了这个错误。什么可能导致这种情况?

回答by Andrew Marshall

gemisn't lying to you, they aren't valid gemcommands.

gem不是在骗你,它们不是有效的gem命令。

Perhaps you're confusing the command line with Bundler? For example, adding

也许您将命令行与 Bundler 混淆了?例如,添加

gem "tilt"

to a Gemfile and running bundle installwill install tilt. But Bundler uses its own syntax, and isn't a shell script. To install tilt using the gembinary directly you'd have to do:

到 Gemfile 并运行bundle install将安装倾斜。但是 Bundler 使用自己的语法,而不是 shell 脚本。要gem直接使用二进制文件安装倾斜,您必须执行以下操作:

gem install tilt

Running gem helpwill give you a list of gem's command line arguments.

运行gem help会给你一个gem命令行参数列表。

回答by David Underwood

You're using the Gemfile syntax and you should be using the commandline syntax. Give this a try:

您正在使用 Gemfile 语法,您应该使用命令行语法。试试这个:

gem install mysql2 -v 0.2.7

回答by BEF Meshesha

Make sure your syntax is correct for more guidelines you can type

确保您的语法正确以获取更多您可以输入的指南

gem help

gem help

To see the acceptable syntax for ruby,

要查看 ruby​​ 可接受的语法,

If you get this error "You don't have write permissions for the /Library"

如果您收到此错误“您没有 /Library 的写权限”

You can always add sudoto elevate privileges.

您可以随时添加sudo以提升权限。

eg. sudo gem install <gemname>

例如。 sudo gem install <gemname>

Using sudobefore your code and that will give you administrative access (after you type your computer password).

sudo在您的代码之前使用,这将为您提供管理访问权限(在您输入计算机密码之后)。

After that you may have to run bundle installto install the gem.

之后,您可能必须运行bundle install以安装 gem。