1

I'm trying to use config/environment.rb to install a ruby gem dependency (because I don't have sudo access to our server; ergo, can't just call gem install hpricot).

I've tried including sundry arguments (:version, :source, :lib) but I still get rake aborted! no such file to load -- hpricot

Update: It turns out that when I remove the plugin which requires hpricot, then I can execute rake gems:install successfully. But that's not very helpful. It means that if I ever move my app, I run into a problem of being unable to rake its gems (because I will have reinstalled the plugin and added features that depend on it).

How is this supposed to work?

Sys: WinXP, Ruby 1.8.7, Rails 2.3.5

JellicleCat
  • 28,480
  • 24
  • 109
  • 162

2 Answers2

2

Rails is trying to load the gem before executing the rake task. This is a known issue with rails 2.x. The only solution I know of is to switch to using bundler to manage gems or manage then manually.

Bundler can be used with rails 2 but it requires some modifications to your application and deployment scripts. This is a good place to start: http://gembundler.com/rails23.html

epochwolf
  • 12,340
  • 15
  • 59
  • 70
  • Thanks for the answer. As I mentioned to @tadman, we don't have bundler installed (and clearly I can't install it). Maybe I should press our IT director to install it. But do you have a workaround? – JellicleCat Aug 15 '11 at 16:38
1

rake gems:install has been deprecated because it never really worked. You can imagine having a gem installer with dependencies to the very gems it's trying to install is a bad idea.

It's advisable to use bundler instead if that's an option.

Bundler allows you to install gems to any destination you want, something specifically intended to side-step the whole "requires sudo" problem you describe. It's often as easy as this:

bundle install --path ~/my_gems/

You can make your Rails 2.3.x application use Bundler by following a few simple steps and from there your life will be a lot easier.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • Thanks. Our IT director told me we just don't have bundler installed (as though he had no inclination to add it). Any workaround? – JellicleCat Aug 15 '11 at 16:37
  • The best workaround is to install it. You can install gems at the user level using a tool like [rvm](http://beginrescueend.com/) or [rbenv](https://github.com/sstephenson/rbenv). How hard can it be for someone to do: `gem install bundler` anyway? – tadman Aug 15 '11 at 19:59
  • Righto. I asked IT, and they said they'd rather just install the gem I wanted (hpricot). So that's what they did. (roll eyes) – JellicleCat Aug 15 '11 at 21:27