blog.mhartl | Michael Hartl's tech blog

2010-02-19

Some rvm gotchas

Filed under: Uncategorized — mhartl @ 12:59

Like many in Rails-land, I started playing with the Rails 3 beta as soon as it came out. And, like many, I discovered to my chagrin that (a) Rails 3 doesn’t play nice with Rails 2.3 and (b) it doesn’t uninstall cleanly. (I ended up manually removing all 3.0.0.beta gems by hand.) If you ask around a bit, you’ll quickly discover a solution to this problem (if you’re running a Mac), which is to run multiple Ruby versions and then install different versions of Rails on different Rubies. This works great in principle, but I ran into a few gotchas in the actual implementation, so I thought I’d share them for the benefit of Google searchers everywhere.

In order to manage the feat of multiple Rubies, the amazing Ruby Version Manager (rvm) by Wayne Seguin is simply essential. Here are the steps I followed:

After installing rvm, I first tried to install the latest version of Ruby 1.8.7, which works with both Rails 2 and Rails 3:

$ rvm install 1.8.7

At this point I got a readline error, but this was covered by the rvm troubleshooting guide:

$ rvm remove 1.8.7; rvm install readline

Unfortunately, the installation still fails to build a makefile:

$ rvm install 1.8.7
.
.
.
FAIL
$ less ~/.rvm/log/ruby-1.8.7-p249/make.error.log

[2010-02-12 08:54:30] make 
make: *** No targets specified and no makefile found.  Stop.

After searching around for a while, I finally found a page (location already forgotten) with the fix, which involves including an explicit path to the readline dependency:

$ rvm remove 1.8.7
$ rvm install 1.8.7 -C --with-readline-dir=/Users/mhartl/.rvm/usr

This still didn’t work, though; on my system (OS X 10.5 Leopard) I got a segfault, which shows up when installing certain gems:

$ gem install metric_fu

/Users/mhartl/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/
spec_fetcher.rb:245: [BUG] Segmentation fault
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.8.0]

Abort trap

Luckily, I have a working Ruby 1.8.7 in /usr/local/bin, so I could check the patchlevel: p174. Since rvm installs the latest version by default (1.8.7-p249 as of this writing), I had to indicate the patchlevel explicitly:

$ rvm remove 1.8.7
$ rvm install 1.8.7-p174 -C --with-readline-dir=/Users/mhartl/.rvm/usr

(Note that this also requires the explicit readline path.)

Finally, I had a working Ruby, but I wanted to set the rvm Ruby as the default, and my system wouldn’t remember it:

$ rvm 1.8.7-p174 --default
$ which ruby 
/Users/mhartl/.rvm/rubies/ruby-1.8.7-p174/bin/ruby
new shell...
$ which ruby
/usr/local/bin/ruby

The solution was to remove the explicit /usr/local/bin path from my .bash_profile file:

before:
  export PATH="/usr/local/bin:$HOME/bin:/usr/local/mysql/bin:$PATH"
  if [[ -s /Users/mhartl/.rvm/scripts/rvm ]] ; then source /Users/mhartl/.rvm/scripts/rvm ; fi

after:
  export PATH="$HOME/bin:/usr/local/mysql/bin:$PATH"
  if [[ -s /Users/mhartl/.rvm/scripts/rvm ]] ; then source /Users/mhartl/.rvm/scripts/rvm ; fi

Wayne Seguin assures me that this step should be unnecessary as long as the PATH appears before the rvm line, but this is the only way I could get it to work on my system. (Since /usr/local/bin is on the system path, all the executables there still run; I’m not sure why I ever included it in .bash_profile in the first place.)

Finally, we’re ready for the raison d’être of all this work: multiple Rubies, multiple Rails. Here’s how to get it working (note the lack of sudo in the gem installations):

$ rvm use 1.8.7
$ gem install rails -v 2.3.5
$ rvm install 1.9.2
$ rvm use 1.9.2
$ gem install rails --pre

Voilà! Now switching between Rails versions is as easy as

$ rvm use 1.8.7

and

$ rvm use 1.9.2
About these ads

14 Comments

  1. I just checked out RVM last night and had a totally different experience. I was having trouble getting vlad to deploy since I upgraded to Snow Leopard, and I had a hunch it had something to do with my version of Ruby (1.8.7), since Leopard came with 1.8.6 and vlad worked fine with that. To find out, I installed RVM and built 1.8.6 and 1.9.1, and installed all of my gems and Rails 2.3.4 with each one. I didn’t have a single problem, nor did I have your readline errors or anything. I don’t think I deviated from the steps in README once. I’ve since donated to RVM and got my whole team to set it up so we can start testing our app in Ruby 1.9. So I guess your mileage may vary, eh!

    Comment by Morgan Currie — 2010-02-19 @ 16:26

  2. Glad to hear for you it went off without a hitch! Yeah, things like this definitely require the YMMV caveat. Sometimes things Just Work™, and I always count my blessings when they do. :-)

    Comment by mhartl — 2010-02-19 @ 17:09

  3. I actually had a great experience with rvm on Snow Leopard. Snow Leopard by default uses 1.8.7 patch 72 (i think its 72) and I needed to use the metasploit framework which cannot run on that specific 1.8.7 patch. I used rvm to install 1.8.7 patch 174 (i think here again) and was able to switch between them seamlessly. I guess I really didn’t go exploring outside ruby1.8.7 however.

    Comment by Jordan West — 2010-02-19 @ 18:25

  4. I’m having an odd problem, after installing RVM and using it to install Ruby 1.9.2 and Rails 3 pre. I did rvm use 1.9.2, the sudo gem install haml, which gave the right success message but when I do a gem list haml isn’t shown. Happened for four gems altogether.

    Any idea why this is happening?

    $ ruby -v
    ruby 1.9.2dev (2009-07-18 trunk 24186) [i386-darwin9.8.0]
    $ which ruby
    /Users/bst/.rvm/rubies/ruby-1.9.2-preview1/bin/ruby

    Comment by BillSaysThis — 2010-02-19 @ 20:44

  5. When using rvm, be sure not to use sudo for gem installs. The way rvm works, it runs as you, not as root. Try this and see if it works:

    $ rvm 1.9.2
    $ gem install haml
    $ gem list haml

    Comment by mhartl — 2010-02-19 @ 22:56

  6. I’m on Snow Leopard and got 1.9.1 to install without a hitch. For 1.8.7, not so good. I followed all the suggestions here and still was getting the make error. What finally worked for me is:
    rvm install 1.8.7-p174 -C --with-readline-dir=/Users/bill/.rvm/usr --reconfigure

    Look under rvm usage to see more on –reconfigure.

    Comment by Lawofaverage — 2010-03-6 @ 10:10

  7. Thanks for this. After installing Rails 3, I’ve never been able to get back to a working version of Rails 2, even with RVM.

    Comment by Gary Bloom — 2010-03-19 @ 12:29

  8. @Gary: try removing the Rails 3.0 beta gems by hand (rm -rf …). That’s what worked for me.

    Comment by Michael Hartl — 2010-03-19 @ 15:28

  9. Thanks, Mike. I finally got 1.8.7 and Rails 2.3.5 working again via RVM. I’m going to stick with that for now, since you disclosed how troublesome it’s going to be to use the 3beta in it’s current state.

    It’s possible that I messed up RVM installation by using sudo at times; I’m not sure. Anyway, when all instructions failed, this worked: http://www.railway.at/2010/02/13/avoiding-rails-3-dependency-hell-with-rvm/, except I installed 2.3.5 instead of 3pre.

    I think it’s too bad that the herokugarden.com and locomotive projects died. There’s a lot to learn for web framework (not to mention programming) novices without having to become a sysadmin when dealing with changes to Ruby, Rails, gems, and databases. There’s a whole book now devoted to deploying Rails. There should be a book on sysadmin devoted to just getting local framework stacks running — heck, just devoted to getting local Rails stacks running, which should include what all those scripts in Bash do.

    Thanks, again, for the Rails Tutorial. I’m looking forward to a way to pay for it. I’d go for a subscription fee.

    Comment by Gary Bloom — 2010-03-22 @ 13:04

  10. RVM Screencast

    Comment by Gary Bloom — 2010-03-24 @ 15:57

  11. Worth noting that `rvm install readline` is now in a ‘packages’ interface: http://rvm.beginrescueend.com/packages/readline/

    Notice how the technique in there does a `rvm remove X` before trying install again, this is usually important after a failed install to ensure everything is clean.

    As for the pathing issue, perhaps also try a `rvm reset`, open a new shell and then try an rvm action.

    ~Wayne

    Comment by Wayne E. Seguin — 2010-03-31 @ 17:21

  12. [...] this didn’t fix my install issue, still got the same error. Luckily I found a post that pointed out that my rvm may not know where readline is (odd, as I used rvm to install [...]

    Pingback by RVM install 1.8.7-p330 fails | Anlek Consulting — 2011-01-3 @ 20:48

  13. When I start your Rss feed it appears to be a ton of garbage, is the problem on my side?

    Comment by website — 2012-05-26 @ 16:57


RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Customized Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 28 other followers

%d bloggers like this: