Change the path for ruby and irb to 1.9.2 in OSX
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
Related videos on Youtube
Cera
Experienced full-stack developer with a passion for the inner workings of systems. I like dancing, cycling, gardening & politics.
Updated on September 18, 2022Comments
-
Cera over 1 year
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 .
-
Cera almost 13 yearsThanks! The path method fixed it, but I think I'll follow your recommendation to use RVM.