问题描述
我为Sinatra项目安装了data_mapper.很好奇,为什么当我执行gem install brew
时,我可以$ which brew
并获取其位置的路径,而不能使用data_mapper?这适用于某些宝石,不适用于其他宝石.
如何验证gem是否已正确安装?是否会检查版本以确保正确下载了gem?
常规解决方案
尝试gem list
获取已安装的宝石列表.
要测试特定的宝石,可以将-i
与正则表达式一起使用:gem list -i "^gem_name$"
.(在此技术的注释中注明为Timo.)
OP的特殊解决方案
如果找不到data_mapper,则可能是gem名称与您期望的名称不同.
此外,如果您只是在执行which brew
来查找brew,就不会找到名为brew的gem,而是会找到brew可执行文件的位置.尝试使用gem which brew
.
如果您通过执行which data_mapper
寻找data_mapper,则可能找不到. which
是用于查找unix可执行文件的unix程序,而data_mapper可能没有.
由于您的目标是验证是否已安装正确版本的gem,请使用gem list
.您可以使用gem list data_mapper
来限制特定的宝石.
要验证它是否已安装并且可以正常工作,您必须尝试require
gem,然后在代码中使用它.
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.
How do I verify a gem is installed properly? Would checking the version assure the gem is downloaded correctly?
General solution
Try gem list
to get the list of gems that are installed.
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.)
Particular solution for OP
If you can't find data_mapper, it may be that the gem name is different from what you expect.
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.
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.
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
.
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!