我正在制作一个宝石,我想在irb上测试它。
我成功运行gem build gemname.gemspec
,然后gem install ./gemname-0.0.0.gem
。宝石名称出现在gem list
本地宝石下。
当我在irb并且需要'gemname'时,它会显示
LoadError: cannot load such file -- gemname
from /Users/iggy/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/iggy/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
from /Users/iggy/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
我已经按this post,this one,this one和其他一些方式查看了答案。仍然得到LoadError
。
我的宝石环境:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.6
- RUBY VERSION: 2.2.1 (2015-02-26 patchlevel 85) [x86_64-darwin14]
- INSTALLATION DIRECTORY: /Users/iggy/.rvm/gems/ruby-2.2.1
- RUBY EXECUTABLE: /Users/iggy/.rvm/rubies/ruby-2.2.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/iggy/.rvm/gems/ruby-2.2.1/bin
- SPEC CACHE DIRECTORY: /Users/iggy/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-14
- GEM PATHS:
- /Users/iggy/.rvm/gems/ruby-2.2.1
- /Users/iggy/.rvm/gems/ruby-2.2.1@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/iggy/.rvm/gems/ruby-2.2.1/bin
- /Users/iggy/.rvm/gems/ruby-2.2.1@global/bin
- /Users/iggy/.rvm/rubies/ruby-2.2.1/bin
- /Users/iggy/.rvm/bin
- /Users/iggy/.nvm/v0.10.36/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
更多信息:
Igors-MacBook-Air:gemname iggy$ which ruby
/Users/iggy/.rvm/rubies/ruby-2.2.1/bin/ruby
确保只有一个ruby在运行(有两个版本,但我将其更改为如下所示)
Igors-MacBook-Air:gemname iggy$ which -a ruby
/Users/iggy/.rvm/rubies/ruby-2.2.1/bin/ruby
当前红宝石版
Igors-MacBook-gemname iggy$ ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
不确定这个命令是做什么的,但我之前看到的其中一个帖子建议运行它:
Igors-MacBook-Air:gemname iggy$ gem env | grep 'RUBY EXECUTABLE'
- RUBY EXECUTABLE: /Users/iggy/.rvm/rubies/ruby-2.2.1/bin/ruby
任何有助于摆脱require 'gemname'
的{{1}}的帮助都将受到高度赞赏。
答案 0 :(得分:0)
问题解决了。
首先,我在gemname文件夹中创建Gemfile
。内部看起来像:
# A sample Gemfile
source "https://rubygems.org"
gemspec
# gem "rails"
重新安装了gem,Gemfile.lock
已创建。
然后我通过bundle exec irb
运行irb,而不是输入irb
。
require 'gemname'
有效。