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 .
Best Answer
Fix your PATH
Get rid of those aliases. Remove them from the
bash_profile
. First of all, check your 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
:Save it, open a new shell and run
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:After the installation, add RVM to your
~/bash_profile
by entering the following into a terminal:Finally, open a new Terminal window and check if RVM works:
This should output "rvm is a function". You can then proceed to install Rubies:
Note: For any further instruction type following in command line
This will give you comprehensive notes on what's and how's.
When this is done, you can set it as default: