9/14/08

Need to run Ruby 1.9 while preserving Ruby 1.8?

I recently decided to start building some production apps using Ruby 1.9. I figured it's getting close enough to full release so why not? Of course the majority of my work still uses Ruby 1.8. So I thought I would jot down some quick notes on how to run them in a non-destructive way. I borrowed the install from this thread [ http://bparanj.blogspot.com/2008/03/installing-ruby-19-on-mac-os-x-with.html?showComment=1218160020000#c441013345691275251 ].

After changing the "/Users/balaparanj/" portions to your own directory, be it your home or otherwise, and compiling all of it, I wrote the following script to easily switch between the two versions as needed:


#!/usr/bin/env ruby
# Usage: sudo ./use_ruby_version.rb 1.9

`rm -f /opt/local/bin/ruby`
case ARGV[0].to_s
when "1.8"
`ln -s /opt/local/bin/ruby1.8 /opt/local/bin/ruby`
when "1.9"
`ln -s /your_ruby1.9_path/ruby19/bin/ruby /opt/local/bin/ruby`
else
`ln -s /opt/local/bin/ruby1.8 /opt/local/bin/ruby`
end


Just chmod it and your ready to go.


chmod 755 use_ruby_version.rb


Now the script assumes a lot of things, like using macports on OS X 10.5 Leopard. Just adjust as needed. Don't forget to change the appropriate areas or it won't work.

Labels:

2 Comments:

  • At September 30, 2008 3:43 AM , Anonymous Anonymous said...

    Use the -f flag and ditch the rm line. Besides being slightly more efficient, it saves you from the chance of some system task, etc. breaking if it runs between the time you rm the old link and create the new one (and the chances of that are quite high since you are exec'ing the shell, and each time you do that the kernel goes looking for another process to run)  
  • At September 30, 2008 8:00 AM , Blogger w3bsmith said...

    Good point. I'll change it.  

Links to this post:

Create a Link

<< Home