djhworld
djhworld

Reputation: 6776

Problem with RVM and gem that has an executable

I've recently made the plunge to use RVM on Ubuntu.

Everything seems to have gone swimmingly...except for one thing. I'm in the process of developing a gem of mine that has a script placed within its own bin/ directory, all of the gemspec and things were generated by Jeweler.

The bin/mygem file contains the following code: -

#!/usr/bin/env ruby
begin
  require 'mygem'
rescue LoadError
  require 'rubygems'
  require 'mygem'
end
app = MyGem::Application.new
app.run

That was working fine on the system version of Ruby.

Now...recently I've moved to RVM to manage my ruby versions a bit better, except now my gem doesn't appear to be working.

Firstly I do this: -

rvm 1.9.2

Then I do this: -

rvm 1.9.2 gem install mygem

Which installs fine, except...when I try to run the command for mygem

mygem

I just get the following exception: -

daniel@daniel-VirtualBox:~$ mygem 
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- mygem (LoadError)
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from /home/daniel/.rvm/gems/ruby-1.9.2-p136/gems/mygem-0.1.4/bin/mygem:2:in `<top (required)>'
    from /home/daniel/.rvm/gems/ruby-1.9.2-p136/bin/mygem:19:in `load'
    from /home/daniel/.rvm/gems/ruby-1.9.2-p136/bin/mygem:19:in `<main>'mygem

NOTE: I have a similar RVM setup on MAC OSX and my gem works fine there so I think this might be something to do with Ubuntu?

Upvotes: 1

Views: 507

Answers (2)

the Tin Man
the Tin Man

Reputation: 160551

Using:

rvm 1.9.2 gem install mygem

is different than how I do my installs of gems inside RVM.

Try:

rvm 1.9.2
gem install mygem

You might also want to try doing gem pristine mygem which will tell Gems to remove the executable and recompile it for the current Ruby.

Another thought: Were you previously using Ruby 1.8+, and just changed to Ruby 1.9+? In Ruby 1.9 the require acts differently when loading modules that are relative to the calling code, say, in a child directory, because '.' was removed from the search path. require_relative was added to give us that capability.

Upvotes: 1

Andrew Grimm
Andrew Grimm

Reputation: 81500

Does doing export RUBYOPT=rubygems help?

Upvotes: 0

Related Questions