29
votes

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?

7
You should not remove (or touch, frankly) the system's Ruby (or Perl or Python). Leave that exactly as it is. The system expects it to be there, and you have no way of knowing in advance how many (or which) things depend on it. In this case, rvm is an excellent tool to manage multiple Ruby interpreters, but there's always a better answer than "remove the default."Telemachus
All the rvm suggestions are a good example of Straw Men. Specifically, you want a system ruby, a ruby for anywhere. You want /opt/local/bin/ruby to be ruby1.9. Now, unix provides the $PATH variable for this, /usr/bin/${ruby binaries} won't be looked for assuming you set up your path correctly, which you have it seems. RVM is a great tool, unless you want to use ruby every day by default.chiggsy
port install ruby19 +nosuffix, btw ;)chiggsy
I want to be able to execute ruby 1.9 scripts from makefiles XCode executes. RVM puts a huge amount of stuff in the environment variables. Anyone know a way to install 1.9 and direct XCode to run it from the makefiles ??peterk

7 Answers

28
votes

You can easy to use port select command, under MacPorts 2.1.3

$sudo port select --set ruby ruby19
26
votes

Install the nosuffix variant instead:

sudo port install ruby19 +nosuffix

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

25
votes

My advice:

$ port uninstall ruby1.9

Then follow this: https://rvm.io/rvm/install/

Then:

$ rvm install 1.9.2
$ rvm --default 1.9.2

You might even rvm install macruby to toy with Cocoa.

19
votes

In the lastest version of macports (2.1.3 or greater) you can use the port select command.

port select --list ruby
sudo port select --set ruby ruby19

For earlier versions of macports you can make a symbolic link to the numbered ruby version. This is the way that macports generally handles switching between different versions of packages.

cd /opt/local/bin
sudo ln -s ruby1.9 ruby
5
votes

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.

2
votes

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'
2
votes

Uninstall ruby version 1.8:
sudo port uninstall ruby
Install ruby version 1.9:
sudo port install ruby19
Reopen terminal