First, let’s look at which version we have installed.
Heinrichs-iMac:~ hbeck$ ruby -v ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
I like things simple, so let’s find a simple way to update this.
Fortunately there is a simple package manager called “Homebrew” which makes life very easy. I like easy.
Installing it takes one line in the terminal:
Heinrichs-iMac:~ hbeck$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
After you install, pay attention to the instructions. You may need to run a command to update it, which you should do.
Some people prefer to manage their versions of Ruby using RVM. I prefer to use rbenv. It’s simpler and lightweight. The documentation for rbenv is here.
Heinrichs-iMac:~ hbeck$ brew update brew install rbenv brew install ruby-build brew install openssl #this part might be optional, if it is, you will get a notice saying, "already installed" CONFIGURE_OPTS=--with-openssl-dir=`brew --prefix openssl` rbenv install 2.0.0-preview1
the last command will take a while to run.
When it finishes, you can run this command to see WHICH versions of ruby are installed
Heinrichs-iMac:~ hbeck$ rbenv versions * system (set by /Users/hbeck/.rbenv/version) 2.0.0-preview1
So the asterisk shows that there is a system ruby (which we already is know 1.8.7) and a cool hotrod 2.0.0-preview1 available.
Since we installed rbenv, we need to tell our $PATH profile to use the settings from rbenv and then “restart” the shell to use the new settings
Heinrichs-iMac:~ hbeck$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile Heinrichs-iMac:~ hbeck$ exec $SHELL -l
Let’s make that hotrod switch! You will need to CAREFULLY type the name of the version, so watch that you get all the characters correct.
Heinrichs-iMac:~ hbeck$ rbenv local 2.0.0-preview1
So let’s verify that we have the correct version.
Heinrichs-iMac:~ hbeck$ ruby -v ruby 2.0.0dev (2012-11-01 trunk 37411) [x86_64-darwin12.4.0]