views:

87

answers:

2

Hi,

I'm working on a console ruby application (not rails!) I will be installing this application on several machines. I was wondering if there is a way i can build it so i dont have to install the gems i'm using for the app on each machine. I'd like to be able to just copy the directory to each machine and run it. Ideally, i'd like to put the gems in the lib folder or something and reference them from there, so i don't have to even install them on my dev machine. Is there a way to do this?

In .net, we call this the "spare tire" principle.

thanks, Craig

+2  A: 

How about using bundler?

Then you can include a Gemfile that specifies all the necssary gems and just run "bundle install" on each machine to pull them down.

If you really want to bundle them with the app run "bundle package" and the gems will be stored in vendor/cache.

chap
i've looked at that and might be the way i end up going. I just wondered if there was no simple way to copy the gems into my lib folder so they dont have to be download? In other languages this is really easy.
fregas
Just updated my answer to show "bundle package" which will package the gems to vendor/cache.
chap
I'm going to try it.
fregas
well i got it to package and copied my stuff over to from my mac to linux server. than i had to install rubygems and bundler itself, because there doesn't seem to be a way to bundle, bundler. after that i tried to run the app again but i got an error that said "sequel is not an installed gem" or something like that, even though i bundled sequel and its in my gemfile. any ideas?
fregas
+1  A: 

You could take the same approach as rails allows and "vendor" your gems. This involves creating a new directory (rails uses vendor/gems) and unpack the gem into this directory, using gem unpack.

You then configure your load path to include all of the sub-folders below that.

Edit

You can configure your load path by doing something like this

Dir.glob(File.join("vendor", "gems", "*", "lib")).each do |lib|
  $LOAD_PATH.unshift(File.expand_path(lib))
end
Steve Weet
cool. how do you configure the load path in ruby?
fregas
As Bundler includes an option to unpack the gems I would go with that.
Steve Weet