开发者

Ruby on Mac OSX via Mac Ports

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 directo开发者_StackOverflow中文版ry 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?


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

$sudo port select --set ruby ruby19


Install the nosuffix variant instead:

sudo port install ruby19 +nosuffix

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


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.


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


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.


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'


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜