简体   繁体   English

尽管已安装,但仍找不到 gem 的 gem

[英]gem which cannot find gem despite it being installed

I've built my first gem but I don't seem to be able to get it to install correctly.我已经构建了我的第一个 gem,但我似乎无法正确安装它。 I can issue the command我可以发出命令

sudo gem install ceilingfish-toto

Which produces the output产生输出

Successfully installed ceilingfish-toto-0.3.6
1 gem installed

But when I then type gem which ceilingfish-toto .但是当我输入gem which ceilingfish-toto I get the output我得到输出

Can't find ruby library file or shared library ceilingfish-toto

Which is very strange because if I go and look in my gems folder I can see all the files installed there这很奇怪,因为如果我去查看我的 gems 文件夹,我可以看到安装在那里的所有文件

# ls -l /opt/local/lib/ruby/gems/1.8/gems/ceilingfish-toto-0.3.6/
total 48
-rw-r--r--  1 root  admin  1053 14 Feb 17:16 LICENSE
-rw-r--r--  1 root  admin  6166 14 Feb 17:16 README.md
-rw-r--r--  1 root  admin   879 14 Feb 17:16 Rakefile
-rw-r--r--  1 root  admin     6 14 Feb 17:16 VERSION
-rw-r--r--  1 root  admin  2477 14 Feb 17:16 ceilingfish-toto.gemspec
drwxr-xr-x  7 root  admin   238 14 Feb 17:16 test

Does anyone know what could cause this?有谁知道这可能导致什么? I think it's complaining because there is a hyphen in the gem name.我认为这是在抱怨,因为 gem 名称中有一个连字符。 You can see the gemspec here http://github.com/ceilingfish/toto你可以在这里看到 gemspec http://github.com/ceilingfish/toto

It's not the hyphen.这不是连字符。

gem which searches for library files in gems, not gems . gem which在 gems 中搜索库文件,而不是 gems Compare:相比:

$ gem which haml
/home/dave/.gem/ruby/1.8/gems/haml-3.0.12/lib/haml.rb
$ ls haml-3.0.12/lib/h*
haml  haml.rb  haml.rbc

Peachy.桃色。 Note the existance of lib/haml.rb .注意lib/haml.rb的存在。

$ gem which rails
ERROR:  Can't find ruby library file or shared library rails
$ ls rails-2.3.8/lib/r*
rails_generator.rb  railties_path.rb  rubyprof_ext.rb  ruby_version_check.rb

There is no lib/rails.rb .没有lib/rails.rb But try:但是尝试:

$ gem which railties_path # not a gem
/home/dave/.gem/ruby/1.8/gems/rails-2.3.8/lib/railties_path.rb

So gem which ceilingfish-toto throws an error even when ceilingfish-toto is installed because there is no lib/ceilingfish-toto.rb file (there's not even a lib folder).因此gem which ceilingfish-toto即使安装了ceilingfish-toto因为没有lib/ceilingfish-toto.rb文件(甚至没有lib文件夹), gem which ceilingfish-toto抛出错误。

gem which ceilingfish-toto looks through the gem require path for a file named ceilingfish-toto.rb. gem which ceilingfish-toto查看 gem 的 gem 需要名为天花板鱼托托.rb 的文件的路径。 Since there isn't one, it returns nothing.因为没有,所以它什么都不返回。 What would work for you is gem which toto , but since lib/ is not included in your gem spec, the lib files are not installed, so it doesn't exist.对您gem which totogem which toto ,但由于lib/未包含在您的 gem 规范中,因此未安装 lib 文件,因此它不存在。

Rerunning rake gemspec might fix the problem.重新运行rake gemspec可能会解决这个问题。

As an aside, you can check whether a gem is installed by its name by using gem list ceilingfish-toto which should show you it is installed, regardless of the files it has(it will also list the versions installed). gem list ceilingfish-toto ,您可以通过使用gem list ceilingfish-toto来检查 gem 是否按其名称安装,它应该显示它已安装,而不管它拥有什么文件(它还会列出安装的版本)。

According to the gem naming recommendations :根据gem 命名建议

If you're adding functionality to another gem, use a dash.如果您要向另一个 gem 添加功能,请使用破折号。 This usually corresponds to a / in the require statement (and therefore your gem's directory structure) and a :: in the name of your main class or module.这通常对应于 require 语句中的 / (因此也是您的 gem 的目录结构)和主类或模块名称中的 :: 。

If this is the case, if your gem is named alpha-beta you need to add a slash (/) to the gem which command如果是这种情况,如果您的 gem 被命名为 alpha-beta,您需要在 gem which 命令中添加一个斜杠 (/)

gem which alpha/beta

OK, so the problem here appears to be that there was a problem with my gemspec file. 好的,所以这里的问题似乎是我的gemspec文件有问题。 From what I can tell there absolutely has to be a file with the name lib/gem-name.rb so in this case I needed lib/ceilingfish-toto.rb . 从我所知道的,绝对必须是一个名为lib/gem-name.rb的文件,所以在这种情况下我需要lib/ceilingfish-toto.rb

This doesn't seem to be true for some other gems to operate correctly. 对于其他一些宝石而言,这似乎并不正确。 For example mime-types or rest-client , even though they do not show up with gem which , they do actually work. 例如mime-typesrest-client ,即使它们没有显示gem which ,它们确实可以工作。

I'm not sure this is entirely correct yet, I'm sure there should be a way to get a gem with a hyphen in the name to behave correctly. 我不确定这是否完全正确,我确信应该有一种方法可以在名称中使用带有连字符的宝石来正确运行。 If I find out I'll post back and let y'all know. 如果我发现我会回复并让你们都知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM