2

In my gem's gemspec, I specify a dependency of another gem (anothergem) with an explicit version, say 1.12.2. If the system already has anothergem version 1.12.1, my gem's executable will require the wrong version. So,

How can I ensure my gem's executable loads the intended version of the gem's dependencies?

To be clear, the executable (mygemexec) should be able to be called from anywhere without the need of bundle exec. Example:

gem install mygem
mygemexec

EDIT: The way I am setting the dependency version in the gemspec is:

spec.add_dependency 'anothergem', '1.12.2'
andrhamm
  • 3,924
  • 4
  • 33
  • 46
  • This should happen already. When you call a gem executable Ruby will set it up so that the correct gem versions are used. A possible issue using the correct dependencies if you call the executable in development, but that doesn’t seem to be what you are asking here. – matt Jan 16 '15 at 13:24
  • @matt Yeah the "should happen already" is what I expected, but it certainly is using an older version of the gem already on my system. I'm not sure what you mean by calling the executable in development – andrhamm Jan 16 '15 at 15:37
  • By development I mean if you try to run the executable file directly from the source folder without installing it as a gem – then the dependencies specified in the gem won’t be used. Are you sure you’ve got the versions the right way round in your question – Ruby will use the latest version by default. I think you will need to give more information about your situation in order to find a solution. – matt Jan 16 '15 at 16:47

0 Answers0