2010-02-14 90 views
6

我已經構建了我的第一塊寶石,但我似乎無法正確安裝它。我可以發出命令即使安裝了它也找不到寶石的寶石

sudo gem install ceilingfish-toto 

它產生輸出

Successfully installed ceilingfish-toto-0.3.6 
1 gem installed 

但是,當我再鍵入gem which ceilingfish-toto。我得到的輸出

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

這是非常奇怪的,因爲如果我去看看我的寶石夾,我可以看到所有的文件安裝在那裏

# 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 

有誰知道這是什麼原因?我認爲這是抱怨,因爲寶石名稱中有一個連字符。您可以在此處看到gemspec http://github.com/ceilingfish/toto

+0

那麼,確實沒有'ceilingfish-toto'文件或共享庫。 – badp

回答

6

gem which ceilingfish-toto通過gem require path查看名爲ceilingfish-toto.rb的文件。由於沒有一個,它什麼都沒有返回。什麼可以爲你工作是gem which toto,但由於lib/不包含在你的gem規範中,所以lib文件沒有安裝,所以它不存在。

重新運行rake gemspec可能會解決問題。另外,您可以使用gem list ceilingfish-toto這個應該顯示它已安裝的名稱,不管它有什麼文件(它也會列出安裝的版本)來檢查是否安裝了gem。

+0

對於'寶石列表',使用_-d_作爲「details」:'gem list -d ceilingfish-toto'來查看它的安裝位置。 –

-1

好的,所以這裏的問題似乎是我的gemspec文件有問題。從我可以告訴那裏絕對必須有一個名爲lib/gem-name.rb的文件,所以在這種情況下,我需要lib/ceilingfish-toto.rb

對於其他一些寶石來說,這似乎並不正確。例如mime-typesrest-client,即使它們不顯示gem which,但它們確實有效。

我不確定這是完全正確的,但我確定應該有一種方法來獲得名稱中帶有連字符的gem以正確行爲。如果我發現我會回覆並讓你們都知道。

7

這不是連字符。

gem which搜索庫文件在寶石,而不是寶石。比較:

$ 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 

桃色。請注意0​​的存在。

$ 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 

沒有lib/rails.rb。但嘗試:

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

所以gem which ceilingfish-toto拋出一個錯誤,即使ceilingfish-toto安裝,因爲沒有lib/ceilingfish-toto.rb文件(有沒有連lib文件夾)。