Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

macos - How can I switch to ruby 1.9.3 installed using Homebrew?

I have installed ruby 1.9.3 using hombrew

brew install ruby

But default 1.8.7 is still used. How can I switch osx to use 1.9.3 as default ruby?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I suggest you take a look at rvm. You can then set it as default with rvm use 1.9.3 --default

But if you are happy with your homebrew install.

Then just change the precedence of directories in the PATH

Here is my /etc/paths

# homebrews should always take precedence
/usr/local/bin

# the default stack
/usr/bin
/bin
/usr/sbin
/sbin

This is important generally for homebrew, else the system version of git, ruby, pg_admin,... will all be used instead of the brew version.

if you say which -a ruby you'll see all the installed rubies, and the precedence in the PATH

eg.

$ which -a ruby
/Users/matthew/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
/Users/matthew/.rvm/bin/ruby
/usr/bin/ruby


UPDATE: I now don't think you should change /etc/paths

Instead you need to check which of .profile, .bashrc, or .bash_login is being loaded in your shell, and just add /usr/local/bin to your path.

For me, I only have a .profile. You can create that file if none of those files already exist in your home directory.

# homebrews should always take precedence
export PATH=/usr/local/bin:$PATH

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...