Iggy Iggy - 4 months ago 16
Ruby Question

Ruby loadError when running require 'gemname' on irb

I am making a gem and I want to test it on irb.

I ran

gem build gemname.gemspec
, then
gem install ./gemname-0.0.0.gem
successfully. The gem name appeared on
gem list
under local gems.

When I am in irb and require 'gemname', it shows

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>'


I have looked at answers by this post, this one, this one,and a few more. Still getting
LoadError
.

My gem environment:

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


More info:

Igors-MacBook-Air:gemname iggy$ which ruby
/Users/iggy/.rvm/rubies/ruby-2.2.1/bin/ruby


Made sure there is only one ruby running (there was two versions, but I changed it to what is shown below)

Igors-MacBook-Air:gemname iggy$ which -a ruby
/Users/iggy/.rvm/rubies/ruby-2.2.1/bin/ruby


Current ruby ver

Igors-MacBook-gemname iggy$ ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]


Not sure what this command does, but one of the posts I saw prior recommended to run this:

Igors-MacBook-Air:gemname iggy$ gem env | grep 'RUBY EXECUTABLE'
- RUBY EXECUTABLE: /Users/iggy/.rvm/rubies/ruby-2.2.1/bin/ruby


Any help to get rid of
require 'gemname'
's
loadError
would be highly appreciated.

Answer

Problem solved.

First I create, on gemname folder, Gemfile. Inside looks like:

# A sample Gemfile
source "https://rubygems.org"
gemspec
# gem "rails"

Reinstalled the gem, Gemfile.lock was created.

Then I ran irb via bundle exec irb instead of typing irb.

require 'gemname' works.

Comments