views:

206

answers:

3

I'm moving a rails app from my desktop to a shared host, and I'm running into trouble with a gem dependency.

I have this declared in my environment.rb:

config.gem "icalendar"

When I first tried starting a console for the app, I got error messages requesting that I rake:install the gem. I used the shared hosting gem install process to install the gem in ~/ruby/gems and confirmed that the gem was there.

ls -rlt ~ruby/gems/gems/icalendar-1.1.0/
total 64
drwxr-xr-x 4 user user  4096 Dec 12 13:15 docs/
drwxr-xr-x 3 user user  4096 Dec 12 13:15 ../
drwxr-xr-x 5 user user  4096 Dec 12 13:18 test/
drwxr-xr-x 3 user user  4096 Dec 12 13:18 lib/

(I replaced the actual user/group here manually)

I then added this to my environment.rb:

ENV['GEM_PATH'] = "/home/USER/ruby/gems"

(Again, actual user replaced)

The next time I ran script/console, the app loaded fine. I then tried to start up the server, and got this error:

Missing these required gems:
icalendar

You're running:
ruby 1.8.7.22 at /usr/bin/ruby
rubygems 1.3.5 at /home/USER/ruby/gems, /usr/lib/ruby/gems/1.8

I tried tweaking the path a bit, but that didn't have any effect. I poked around a bit here and on google at large and didn't see anything that directly addressed this problem--I would think that the console and server would both use the GEM_PATH in the environment config. Doesn't look like a permissions issue either. Any ideas? Thanks for the help with this.

A: 

If you are using Passenger, you should use a small trick to get the GEM_PATH environment variable working. Follow this tutorial.

Simone Carletti
A: 

in the similar situation (when the server started, some pathes were not included in LOAD_PATH variable) adding

require 'rubygems'

before including other gems helped me.

or you can manually add path to your gem

$LOAD_PATH << '/home/USER/ruby/gems/gems/icalendar-1.1.0/lib'
aaz
A: 

Be sure to set the environment variable before the initializer block:

ENV['GEM_PATH'] = '...'
Gem.clear_paths

Rails::Initializer.run ...
mislav
yep, I was specifying ENV['GEM_PATH'] right at the top of the file. What appears to have fixed it was also adding Gem.clear_paths. Thanks!
greg