Playing nicely: Notes on installing RVM + Passenger
Sam Phillips, December 30th, 2009 11:13 pm
Upon installing a new Mac for home development, I decided to try out a few new technologies – RVM was one of them. It was relatively painless in terms of commands; but it did require a bit of a mindset shift to understand how to debug it. Hopefully this will help someone; the steps below should work for linux machines too, albeit with some slight changes to paths.
RVM, Ruby Version Manager, allows you to run multiple ruby versions on the same machine. This is good if you want to test upgrades etc. For me, a pleasant side effect was being forced away from using the system version of ruby. Relying on the system version (and system gems… more on that in a bit!) seemed a little lazy, and was always a bit of a pain when unraveling dependencies and moving stuff live.
Another complementary tool, which I’ll hopefully blog about separately, is bundler. Do yourself a big favour and don’t try to install both at once; it can get a mind-boggling. Get to the point where you’re happy with one of the two, and then start on the other.
The RVM site is full of useful information, although it’s not always super easy to find what you need. The stuff on installation is vital (for the record, the gem version worked for me – in fact, rvm is the only gem I have installed on the system ruby).
Once installed, I installed ruby 1.8.7 with:
$ rvm install 1.8.7
The system was already running 1.8.7, so I figured this was probably the best place to start. The plan is run within this version by default, and to use other versions as appropriate.
Once installed, activate with:
$ rvm use 1.8.7
This will switch the ruby version for the current terminal. Only. This wasn’t immediately clear to me; if you want to switch for all terminals, add the default flag:
$ rvm use 1.8.7 --default
Fire up a new terminal, and it should now also be running the same version of ruby. Check with ‘ruby -v’:
$ ruby -v
ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin10.2.0]
To be sure that you’re using the version of ruby you expect, there are a few things you can check:
$ which ruby
/Users/samphillips/.rvm/ruby-1.8.7-p248/bin/ruby
If you get ‘/usr/bin/ruby’ instead, you’re still using the system version.
RubyGems is installed separately for each ruby instance. To check that the ‘gem’ command is hitting the right place, again, break out ‘which’:
$ which gem
/Users/samphillips/.rvm/ruby-1.8.7-p248/bin/gem
Another good check is ‘gem env’:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin10.2.0]
- INSTALLATION DIRECTORY: /Users/samphillips/.rvm/gems/ruby-1.8.7-p248
- RUBY EXECUTABLE: /Users/samphillips/.rvm/ruby-1.8.7-p248/bin/ruby
- EXECUTABLE DIRECTORY: /Users/samphillips/.rvm/gems/ruby-1.8.7-p248/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /Users/samphillips/.rvm/gems/ruby-1.8.7-p248
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://gemcutter.org/"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gemcutter.org/
Again, if you’re seeing references to directories like these:
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
Then your switch hasn’t worked.
Some reasons I’ve found why switching hasn’t worked:
- It’s apparently possible to drop the ‘use’ keyword when choosing ruby versions. I’ve learned not to do this; firstly it doesn’t give you a nice confirmation that it’s worked, and secondly it didn’t seem to work correctly (perhaps the two are related…)
- Similarly, although you’ve assigned the ‘default’ version of ruby, running ‘rvm use default’ doesn’t seem to work properly all the time.
If keeping to the full ‘rvm use xxx –default’ command doesn’t help you, it might be worth re-installing. This is easy; switch back to the system version of ruby (’rvm use system’), delete the .rvm directory in your home directory and uninstall the gem. It seems that my mistake with my original install was a classic one:
Too much sudo
We’ve got very used to installing gems, and doing anything to do with them, with sudo. With rvm, you don’t need to do this and it will lead to confusing results, as the docs point out at length. Every time you use sudo, you’re going to be messing with the system ruby version (as this is in root’s path), and weird results will follow.
To summarise: use sudo to install the gem on system ruby, and then leave the sudo well alone.
Passenger
If you’re using with passenger + apache, first install the passenger gem against your rvm ruby version:
$ rvm use 1.8.7
$ gem install passenger
[snip]
$ passenger-install-apache2-module
Note the lack of sudo. The module installer will suggest the apache config syntax. This needs changing slightly, as per the docs –
$ cat /etc/apache2/other/passenger.conf
LoadModule passenger_module /Users/samphillips/.rvm/gems/ruby-1.8.7-p248/gems/passenger-2.2.8/ext/apache2/mod_passenger.so
PassengerRoot /Users/samphillips/.rvm/gems/ruby-1.8.7-p248/gems/passenger-2.2.8
PassengerRuby /Users/samphillips/.rvm/bin/passenger_ruby
(restart apache…)
The last line will point apache at your rvm ruby version. When using passenger with rvm, switch the rvm version with the following syntax:
$ rvm use 1.9.1 --default --passenger
I was confused for a number of minutes when gems installed on my rvm version of ruby weren’t available to apache; not doing this was why.
RVM works nicely already, and has potential to do lots of good. If you’ve got any problems, hop on to #rvm on irc.freenode.net, where friendly folks will help you out.








