Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I recently used Homebrew to install Ruby 1.9.2 on OSX. The binary for the new version seems to be in /usr/local/bin.

When I type "ruby" (or "irb") in a terminal, I want the binaries corresponding to 1.9.2 to be executed. At the moment I'm doing this with dirty aliases in my ~/.bash_profile:

alias 'ruby'=/usr/local/bin/ruby
alias 'gem'=/usr/local/bin/gem
alias 'irb'=/usr/local/bin/irb

Is there a better, more "correct" way to do this? I've heard people mention that I may need to fix my path?

Additionally, while the alias works for the 'ruby' and 'gem', it doesn't seem to work for the irb binary - when I type 'irb' it still loads a version of interactive ruby that can't handle syntax specific to ruby 1.9 .

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Fix your PATH

Get rid of those aliases. Remove them from the bash_profile. First of all, check your path.

echo $PATH

Here, /usr/local/bin should take precedence over /usr/bin. If this isn't the case, something is wrong. Try if the following works, when you add this line to ~/.bash_profile:

export PATH=/usr/local/bin:$PATH

Save it, open a new shell and run

which -a ruby

Now you should see that /usr/local/bin/ruby is used, whereas /usr/bin/ruby comes second (this is the default ruby 1.8.7 of OS X).


Alternative: Install RVM

For a better Ruby experience I would recommend you remove the Homebrew installation of Ruby altogether and install RVM, the Ruby Version Manager. Why? Because it allows you to switch between your locally installed Rubies and Gems.

Install git over Homebrew if you haven't already. Then:

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

After the installation, add RVM to your ~/bash_profile by entering the following into a terminal:

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile

Finally, open a new Terminal window and check if RVM works:

type rvm | head -1

This should output "rvm is a function". You can then proceed to install Rubies:

rvm install 1.9.2

Note: For any further instruction type following in command line

rvm notes

This will give you comprehensive notes on what's and how's.

When this is done, you can set it as default:

rvm --default use 1.9.2
share|improve this answer
    
Thanks! The path method fixed it, but I think I'll follow your recommendation to use RVM. –  Cerales Aug 8 '11 at 11:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.