Loading local gems in cPanel shared hostma. 25 april 2011
I had some trouble today figuring out why my Redmine installation wouldn't start running on my shared server. I received the following error in my log/mongrel.log file:
** Starting Rails with production environment... Missing the i18n 0.4.2 gem. Please `gem install -v=0.4.2 i18n`
Now, I had finally gotten rid of this problem while using SSH by running
export GEM_PATH=/home/<my username>/ruby/gems
in terminal (or adding it to .bashrc), resulting in successful rake commands and running the server with WEBrick. However, Mongrel seemed to have serious issues with loading the gems in my local files.
This should be solved by adding
ENV['GEM_PATH']= "/home/<my username>/ruby/gems:/usr/lib/ruby/gems/1.8"
to the environment.rb file, but it did not. Apparently this is because Mongrel loads rubygems by itself, ignoring any environment variables set after this. Therefore, the below fine hack by Rui Lopez found on this page, became necessary:
ENV['GEM_PATH']= "/home/<my username>/ruby/gems:/usr/lib/ruby/gems/1.8" require 'rubygems'; Gem.clear_paths; Gem.instance_variable_set(:@searcher, nil)
As Rui puts it himself:
[This] clears the internal cache used by rubygems, and forces it to re-read the GEM_PATH env. variable.
As he also points out, it might not be the cleanest hack, but it works. And that makes me happy.