制作Ruby Gem - 无法加载这样的文件 [英] Making a Ruby Gem - Cannot Load Such File
问题描述
我试图使用 http://中的说明构建Ruby gem。 guides.rubygems.org/make-your-own-gem/ 。以下似乎工作正常,生成* .gem文件。
gem build mygem.gemspec
code>
以下内容似乎也是成功的(只有以 sudo
开头) :
sudo gem install mygem-0.0.1.gem
但是,当我试图在irb中使用 require'mygem'
时,出现以下错误:
LoadError:无法加载此文件 - mygem
我在Stackoverflow上看到过类似的错误,但一直没能弄清楚在我的具体情况中出了什么问题。我可以要求其他宝石(不是我的)没有问题。我的宝石确实出现在 gem list
的输出中,但它不会加载require。
我是使用rbenv,这对我来说是全新的。
以下是 gem env
的输出:
-
RUBYGEMS VERSION:2.4.5
-
RUBY VERSION:2.1.5(2014 -11-13 patchlevel 273)[x86_64-darwin14.0]
-
-
安装目录:/Users/speersj/.rbenv/versions/2.1.5/lib /ruby/gems/2.1.0
-
RUBY EXECUTABLE:/Users/speersj/.rbenv/versions/2.1.5/bin/ruby
-
可执行目录:/Users/speersj/.rbenv/versions/2.1.5/bin
-
SPEC CACHE DIRECTORY:/Users/speersj/.gem/specs
-
系统配置目录:/Users/speersj/.rbenv/versions/2.1.5/etc
-
x86_64-darwin-14
-
创业板路径:
-
/Users/speersj/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0
-
/Users/speersj/.gem/ruby/2.1.0
-
-
创业板配置:
-
:update_sources => true
-
:verbose => true
-
-
:backtrace => false
-
:bulk_threshold => 1000
/ b> -
远程来源:
-
-
SHELL PATH:
-
/Users/speersj/.rbenv/versions/2.1.5/bin
-
/Users/speersj/.rbenv/libexec
-
/Users/speersj/.rbenv/plugins/ruby- build / bin
-
/Users/speersj/.rbenv/shims
-
/ Users /speersj/.rbenv/bin
-
/Library/Frameworks/Python.framework/Versions/3.4/bin
$ b $ - / usr / local / sbin
- sbin
-
/ sbin
-
/ usr / local / bin
-
- / usr / local / smlnj / bin li>
/ usr / local / bin
li>
Gemspec:
Gem :: Specification.new do | spec |
spec.name ='mygem'
spec.version ='0.0.1'
spec.date ='2015-01-05'
spec.summary =mygem
spec.description =试图建立一个宝石
spec.authors = [speersj]
spec.email =#我的电子邮件在这里
spec.files = [' lib / command.rb','lib / connection.rb']
spec.homepage =''
spec.license ='MIT'
end
$ c $
您的 spec.files
条目 gemspec
不包含 mygem.rb
文件,因此文件不会在gem中建成。只有在此条目中列出的文件才会包含在最终的宝石中。
最简单的解决方案是只添加 mygem.rb
spec.files = ['lib / command.rb','lib / connection.rb ','lib / mygem.rb']
这是一个相当简单的修复方法,您可能想要做更灵活的事情,比如使用 <$ c 实际上 Rubygems指南建议你做这样的事情(文本来自该部分的末尾) : 如果您已将更多文件添加到您的gem,请务必记得在发布新文件之前将它们添加到您的gemspec文件数组中宝石!出于这个原因(其中包括),许多开发人员使用锄头 珠宝商, Rake , Bundler 或只是一个动态的gemspec 。 另外,您确实需要修复您的权限问题,您不需要 I'm attempting to build a Ruby gem using the instructions at http://guides.rubygems.org/make-your-own-gem/. The following seems to work fine and a *.gem file is generated. The following also appears to be successful (only if prefaced with However, when I attempt to I've seen similar errors around Stackoverflow but haven't been able to figure out what's going wrong in my specific situation. I am able to require other gems (not mine) without problems. My gem does show up in the output of FWIW I am using rbenv, which is brand new to me. Here is the output of RUBYGEMS VERSION: 2.4.5 RUBY VERSION: 2.1.5 (2014-11-13 patchlevel 273) [x86_64-darwin14.0] INSTALLATION DIRECTORY: /Users/speersj/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0 RUBY EXECUTABLE: /Users/speersj/.rbenv/versions/2.1.5/bin/ruby EXECUTABLE DIRECTORY: /Users/speersj/.rbenv/versions/2.1.5/bin SPEC CACHE DIRECTORY: /Users/speersj/.gem/specs SYSTEM CONFIGURATION DIRECTORY: /Users/speersj/.rbenv/versions/2.1.5/etc RUBYGEMS PLATFORMS: ruby x86_64-darwin-14 GEM PATHS: /Users/speersj/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0 /Users/speersj/.gem/ruby/2.1.0 GEM CONFIGURATION: :update_sources => true :verbose => true :backtrace => false :bulk_threshold => 1000 REMOTE SOURCES: SHELL PATH: /Users/speersj/.rbenv/versions/2.1.5/bin /Users/speersj/.rbenv/libexec /Users/speersj/.rbenv/plugins/ruby-build/bin /Users/speersj/.rbenv/shims /Users/speersj/.rbenv/bin /Library/Frameworks/Python.framework/Versions/3.4/bin /usr/local/bin /usr/local/sbin /usr/local/heroku/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /usr/local/bin /usr/local/smlnj/bin Gemspec:
The The simplest solution would be to just add This is a fairly simple fix, you might want to do something more flexible like using a In fact the Rubygems guide suggests you do something like this (text is from the end of that section): If you’ve added more files to your gem, make sure to remember to add them to your gemspec’s files array before publishing a new gem! For this reason (among others), many developers automate this with Hoe, Jeweler, Rake, Bundler, or just a dynamic gemspec.
Also, you really do need to fix your permissions problem, you shouldn’t need 这篇关于制作Ruby Gem - 无法加载这样的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b $ pre $ spec $ cf $ D $ [$ lib $ / code> ** / *。rb']
sudo
将宝石安装到您自己的主目录中。gem build mygem.gemspec
sudo
):sudo gem install mygem-0.0.1.gem
require 'mygem'
inside irb, I get the following error:LoadError: cannot load such file -- mygem
gem list
but it will not load with require.gem env
:
Gem::Specification.new do |spec|
spec.name = 'mygem'
spec.version = '0.0.1'
spec.date = '2015-01-05'
spec.summary = "mygem"
spec.description = "Attempting to build a gem"
spec.authors = ["speersj"]
spec.email = # my email here
spec.files = ['lib/command.rb', 'lib/connection.rb']
spec.homepage = ''
spec.license = 'MIT'
end
spec.files
entry of your gemspec
doesn’t include the mygem.rb
file, so that file won‘t be in the gem when it is built. Only files listed in this entry will be included in the final gem.mygem.rb
to the array:spec.files = ['lib/command.rb', 'lib/connection.rb', 'lib/mygem.rb']
Dir
glob:spec.files = Dir['lib/**/*.rb']
sudo
to install gems into your own home directory.