Ruby-on-rails – Rails on Passenger not recognizing RVM

passengerruby-on-railsrvm

I have shifted to ree using rvm by:

rvm use ree@mygemset

and installed kaminari gem through Gemfile and bundle install.

But Phusion passenger seems to still look for the gem in system default directory. It says:

Error message:
    Could not find kaminari-0.10.4 in any of the sources (Bundler::GemNotFound)

What do I missing? Rails need any specific configuration to recognize the current ruby version and gemset I am using??

Best Answer

You need to instruct Passenger to load RVM and then setup the environment for your gemset. The easiest way to go about this involves three steps:

  1. Create a .rvmrc file: In the root of your rails project, create a file called .rvmrc that contains the RVM command you would use to load up your gemset. For example:

    rvm use ree@gemset
    
  2. Trust the .rvmrc file: Once you've deployed your new .rvmrc file to your server, change directories into your rails project. RVM should ask you if you want to trust your .rvmrc file; simply follow the instructions and type yes when asked. If the prompt does not appear, use the following command to trust your .rvmrc:

    rvm rvmrc trust
    

    Note: If you wish to automatically trust all .rvmrcs, it is a simple matter of adding:

    rvm_trust_rvmrcs_flag=1
    

    to your personal or system wide rvmrc (~/.rvmrc and /etc/rvmrc, respectively).

  3. Instruct passenger to set up the RVM environment: Instruct passenger to load up RVM and use the gemset in your .rvmrc file by creating a new file in your Rails config directory called setup_load_paths.rb (so config/setup_load_paths.rb in all). The file should contain the contents of https://gist.github.com/870310:

    if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
      begin
        rvm_path     = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
        rvm_lib_path = File.join(rvm_path, 'lib')
        $LOAD_PATH.unshift rvm_lib_path
        require 'rvm'
        RVM.use_from_path! File.dirname(File.dirname(__FILE__))
      rescue LoadError
        raise "RVM ruby lib is currently unavailable."
      end
    end
    
    # This assumes Bundler 1.0+
    ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
    require 'bundler/setup'
    

    Now when you restart your app (touch tmp/restart.txt) you should be good to go.

You should note that Passenger can only run one version of Ruby at a time; if Passenger was set up under something other than ree, you will probably have to reinstall Passenger and/or redo the wrapper script it generates.

Related Topic