1

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.

Community
  • 1
  • 1
Iggy
  • 5,129
  • 12
  • 53
  • 87
  • Try `require 'rubygems'` and then require the gem that gave you the error. – 13aal Jul 01 '16 at 21:10
  • 1
    As a note, putting a capital `N` in your gem name is going to drive people nuts. The convention is lower-case only. The packages that do flout this rule stand out as irregular. Do you have a `gemName.rb` file? – tadman Jul 01 '16 at 21:14
  • @13aal I did that and it returns false. It seems like it was already loaded.When I require 'gemname' it returns the error. I will change the camelcase. I do have the gemname.rb inside folder named lib. The gem follow convention from http://guides.rubygems.org/make-your-own-gem/ (not exactly the same)- it has at least gemname.gemspec, lib folder, and gemname.rb – Iggy Jul 01 '16 at 21:35

1 Answers1

0

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.

Iggy
  • 5,129
  • 12
  • 53
  • 87