开发者

making ruby 1.9 default on os x [duplicate]

This question already has answers here: Installing RVM (Ruby Version Manager) 开发者_如何转开发 (2 answers) Closed 8 years ago.

How do I make ruby 1.9 the default version to use instead of the 1.8.x that is by default installed on os x?

Thanks.


As of v2.1.3, the "correct" MacPorts way of setting a specific version of a package as the default is to use the select command, like this:

sudo port select --set ruby ruby19

There doesn't appear to be any documentation about this command in the MacPorts Guide. You can however run port help select to get a very limited description. This functionality replaces the +nosuffix "variant" style of setting the default version.


I recommend installing the RVM tool from http://rvm.beginrescueend.com/ (it has instructions on installing it

It allows you to have multiple versions of ruby and gems. After installing RVM, then install the Ruby 1.9 you want, using:

rvm install ruby-1.9.1

To make it the default one:

rvm --default ruby-1.9.1

After this, it will be the default ruby.


RVM is great for setting up multiple environments with different versions of Ruby and gems.

If you however just want to have Ruby 1.9 you can simply install it using MacPort. It will take precedence over the one already installed by default on OS X.

  1. Download MacPort if you haven't already. It's the Mac package manager.
  2. On a Terminal, use MacPort to install Ruby 1.9 and RubyGems
    sudo port selfupdate
    sudo port install ruby19
    sudo port install rb-rubygems

You should then have Ruby 1.9 installed and ahead on the path. Do a ruby -v to check. Use Ruby gems to install any other Ruby components like Rails.

Ports are installed in the /opt/local/bin directory and MacPort updates the PATH environment variable so that these are picked up before the /usr/bin pre-installed packages.


you could create an alias rather than a symlink...this way both versions are left intact. add the following line to .profile in user's home folder (create if doesn't exist):

alias ruby='/opt/local/bin/ruby1.9'

then source the file:

source .profile

hope that helps :)


I would say skip the rvm.

In my case, MacPorts did prepend /opt/local/bin to my path, but installed ruby 1.9 as ruby1.9. (Leaving ruby -> /usr/bin/ruby.)

By far the easiest way to fix:

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

Poof. Done.

Exact commands:

nsmcs-macbook-pro:~ nsmc$ which ruby
/usr/bin/ruby
nsmcs-macbook-pro:~ nsmc$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
nsmcs-macbook-pro:~ nsmc$ which ruby1.9
/opt/local/bin/ruby1.9
nsmcs-macbook-pro:~ nsmc$ sudo su
Password:
sh-3.2# cd /opt/local/bin/
sh-3.2# ls -l ruby*
-rwxr-xr-x  2 root  admin  9040 Feb 16 07:43 ruby1.9
sh-3.2# ln -s ruby1.9 ruby
sh-3.2# which ruby
/opt/local/bin/ruby
sh-3.2# ruby --version
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜