tags:

views:

217

answers:

4

I'm new to both Ruby and to Mac OSX, though I do have a fair amount of experience with Unix commands. I just installed Ruby 1.9 via a MacPorts command (port install ruby19). I then needed to do a find from root just to figure out where it went, which turned out to be: /opt/local/var/macports/software/ruby19/1.9.1-p376_0/opt/local/bin/ruby1.9.

The current version of Ruby (1.8.6) runs via /usr/bin/ruby, which is a symbolic link to /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby where Current is a symbolic link to a directory called 1.8.

I'd like to make Ruby 1.9 my default (along with related tools like irb), and while I can manage to do that, I'd like to know if there's a conventional way. Should I copy or link the MacPorts path to /System/Library/Frameworks/Ruby.framework/Versions/1.9 and then point Current to 1.9? (I'd also have rename or copy the executables: ruby1.9 to ruby, irb1.9 to irb, etc.) Or should I just blow away the /usr/bin/ruby link (and /usr/bin/irb, etc) and create new ones pointing to the MacPorts version?

+3  A: 

I would highly recommend RVM. It takes a bit of reading, but once you have it installed you can install a ruby with rvm install 1.9 (or jruby, ree, 1.8, etc), and switch between them with rvm 1.9. Each ruby version will also have its own, completely isolated set of rubygems.

Matt Briggs
+5  A: 

My advice:

$ port uninstall ruby1.9

Then follow this: http://rvm.beginrescueend.com/rvm/install/

Then:

$ rvm install 1.9.2
$ rvm --default 1.9.2

You might even rvm install macruby to toy with Cocoa.

Amadan
+1 here, and checkout homebrew for other package management http://github.com/mxcl/homebrew
Jed Schneider
Thanks! Rvm seems like a bit of a commitment, but probably worth the effort.
Greg Charles
rvm has a bunch of options, but for starters, you can get by only with these three: `rvm install` to get a new ruby, `rvm use` to switch versions, and once in a while `rvm update` to get the new stuff. Everything else you can learn at your leisure, when you need it (e.g. multiversion testing).
Amadan
+1  A: 

Install the nosuffix variant instead:

sudo port install ruby19 +nosuffix

Your newer ruby version should now take precedence over the preinstalled one.

You
Thanks, that's very helpful. I didn't see that option.
Greg Charles
+1  A: 

The ruby1.9 binary should be installed in /opt/local/bin; if it's not, you may not have activated the port.

The easiest way to make Ruby 1.9 the default root is to create an alias for ruby to ruby1.9. If you're using Bash, you can do that by putting this in your Bash config file:

alias ruby='/opt/local/bin/ruby1.9'
mipadi
Thanks for pointing that out. I do have /opt/local/bin/ruby1.9. I'll probably enable it with a symbolic link rather than an alias, but either way would work.
Greg Charles