Rails on Passenger not recognizing RVM
Asked Answered
M

4

14

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??

Metatarsal answered 15/3, 2011 at 4:12 Comment(2)
that's not looking in your default system directory. it's looking for the gem in the sources you told bundler to look. look at your Gemfile again. also, how did you install your kaminari gem? and what does gem list say?Burkitt
What is your passenger version? How to you have it installed? (standalone or with another web server in front of it, if so which? apache or nginx)Logbook
S
30

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.

Shiri answered 15/3, 2011 at 4:31 Comment(2)
On my particular setup I had to run the "rvm use ree@gemset" in console before "bundle install" as .rvm file was not executed upon entry to directory in shell.Broadcast
The above is true up to and including Passenger version 3. Passenger 4 allows multiple ruby versions: Apache & NginxTalus
M
2

Just an additional note to step3 of the Marked (Broandon's) answer, because I didn't get my Passenger3 up and run by using those codes.

The error message is as below:

*** Phusion Passenger: no passenger_native_support.bundle found for the current Ruby interpreter. Compiling one...
# mkdir -p /Users/jerry/.rvm/gems/ruby-1.9.3-p194@xxx/gems/passenger-3.0.18/ext/ruby/ruby-1.9.3-x86_64-macosx
# cd /Users/jerry/.rvm/gems/ruby-1.9.3-p194@xxx/gems/passenger-3.0.18/ext/ruby/ruby-1.9.3-x86_64-macosx
Unable to locate the RVM path. Your RVM installation is probably too old. Please update it with 'rvm get head && rvm reload && rvm repair all'.

Referring to the message "Unable to locate the RVM path", I checked the RVM Documentation https://rvm.io/integration/passenger/

Edit config/setup_load_paths.rb to this:

if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
  begin
    gems_path = ENV['MY_RUBY_HOME'].split(/@/)[0].sub(/rubies/,'gems')
    ENV['GEM_PATH'] = "#{gems_path}:#{gems_path}@global"
    require 'rvm'
    RVM.use_from_path! File.dirname(File.dirname(__FILE__))
  rescue LoadError
    raise "RVM gem is currently unavailable."
  end
end

# If you're not using Bundler at all, remove lines bellow
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'

Problem solved!

Myrwyn answered 28/11, 2012 at 5:56 Comment(0)
B
1

I followed the suggested answer and it moved me forward but then I got an error message:

RVM - Ruby integration was extracted to a separate gem, it should be installed by default >with RVM, remove the $LOAD_PATH.unshift line and all should be fine again. Visit https://rvm.io/integration/passenger for more details. (RuntimeError)

Passenger now have a gem. My mistake was not installing it in the ruby version and gemset I was using. Once I did that - everything worked sweet.

Beeman answered 4/9, 2013 at 21:11 Comment(0)
B
0

Remove the config/setup_load_paths.rb file for Passenger 4. It is not needed.

Brantbrantford answered 2/6, 2014 at 15:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.