如何检查是否安装了宝石?

时间:2021-07-20 04:09:38

I installed data_mapper for a Sinatra project. Curious, why is it when I do gem install brew, I can $ which brew and get the path of its location and can't for data_mapper? This works for some gems and doesn't for others.

我为Sinatra项目安装了data_mapper。好奇,为什么当我做宝石安装brew时,我可以$ brew酿造并获取其位置的路径而不能用于data_mapper?这适用于某些宝石,而不适用于其他宝石。

How do I verify a gem is installed properly? Would checking the version assure the gem is downloaded correctly?

如何验证宝石安装是否正确?检查版本会确保gem正确下载吗?

2 个解决方案

#1


34  

General solution

一般解决方案

Try gem list to get the list of gems that are installed.

尝试使用gem list获取已安装的gem列表。

To test for a particular gem, you can use -i with a regex: gem list -i "^gem_name$". (Credit to Timo in the comments for this technique.)

要测试特定的gem,可以使用-i和正则表达式:gem list -i“^ gem_name $”。 (在对这项技术的评论中感谢蒂莫。)

Particular solution for OP

OP的特殊解决方案

If you can't find data_mapper, it may be that the gem name is different from what you expect.

如果找不到data_mapper,可能是gem名称与您的期望不同。

Also, if you're just doing which brew to find brew, you aren't finding the gem called brew, you're finding the location of the brew executable. Try gem which brew instead.

此外,如果您正在使用brew查找brew,您没有找到名为brew的gem,您将找到brew可执行文件的位置。试试brew而不是brew。

EDIT:

编辑:

If you're looking for data_mapper by doing which data_mapper, you probably won't find it. which is a unix program for finding unix executables, and data_mapper probably doesn't have one.

如果您正在通过执行哪个data_mapper来查找data_mapper,您可能无法找到它。这是一个用于查找unix可执行文件的unix程序,而data_mapper可能没有。

Since your goal is to verify a gem is installed with the correct version, use gem list. You can limit to the specific gem by using gem list data_mapper.

由于您的目标是验证使用正确版本安装gem,请使用gem list。您可以使用gem list data_mapper限制特定的gem。

To verify that it's installed and working, you'll have to try to require the gem and then use it in your code.

要验证它是否已安装并正常工作,您必须尝试使用​​gem,然后在代码中使用它。

#2


33  

In case you want to use the check in a script, this gives a better output (true or false) and appropriate exit code:

如果您想在脚本中使用检查,则会提供更好的输出(true或false)和适当的退出代码:

gem list -i <gem_name>

Alternatively add the version option:

或者添加版本选项:

gem list -i <gem_name> -v version

#1


34  

General solution

一般解决方案

Try gem list to get the list of gems that are installed.

尝试使用gem list获取已安装的gem列表。

To test for a particular gem, you can use -i with a regex: gem list -i "^gem_name$". (Credit to Timo in the comments for this technique.)

要测试特定的gem,可以使用-i和正则表达式:gem list -i“^ gem_name $”。 (在对这项技术的评论中感谢蒂莫。)

Particular solution for OP

OP的特殊解决方案

If you can't find data_mapper, it may be that the gem name is different from what you expect.

如果找不到data_mapper,可能是gem名称与您的期望不同。

Also, if you're just doing which brew to find brew, you aren't finding the gem called brew, you're finding the location of the brew executable. Try gem which brew instead.

此外,如果您正在使用brew查找brew,您没有找到名为brew的gem,您将找到brew可执行文件的位置。试试brew而不是brew。

EDIT:

编辑:

If you're looking for data_mapper by doing which data_mapper, you probably won't find it. which is a unix program for finding unix executables, and data_mapper probably doesn't have one.

如果您正在通过执行哪个data_mapper来查找data_mapper,您可能无法找到它。这是一个用于查找unix可执行文件的unix程序,而data_mapper可能没有。

Since your goal is to verify a gem is installed with the correct version, use gem list. You can limit to the specific gem by using gem list data_mapper.

由于您的目标是验证使用正确版本安装gem,请使用gem list。您可以使用gem list data_mapper限制特定的gem。

To verify that it's installed and working, you'll have to try to require the gem and then use it in your code.

要验证它是否已安装并正常工作,您必须尝试使用​​gem,然后在代码中使用它。

#2


33  

In case you want to use the check in a script, this gives a better output (true or false) and appropriate exit code:

如果您想在脚本中使用检查,则会提供更好的输出(true或false)和适当的退出代码:

gem list -i <gem_name>

Alternatively add the version option:

或者添加版本选项:

gem list -i <gem_name> -v version