Friday, March 5, 2010

switching between ruby 1.8 and 1.9

So if you followed homebrew + ruby 1.9 + rails 3.0 instructions from the previous post,  you now have ruby 1.9.x in your /usr/local/bin, and ruby 1.8.x in your /usr/bin. Same applies to gems, and thus rails.
Let's say you want switch environments, how do you do that?

Well it's simple. You want to put either /usr/bin or /usr/local/bin in front in your shell's $PATH variable. And you can do this with simple aliases:

alias ruby19="export PATH=/usr/local/bin:/usr/bin:`echo $PATH| sed -E 's/\/usr(\/local){0,1}\/bin[:]{0,1}//g'`"
alias ruby18="export PATH=/usr/bin:/usr/local/bin:`echo $PATH| sed -E 's/\/usr(\/local){0,1}\/bin[:]{0,1}//g'`"

now you can switch simply by running ruby18 or ruby19 in a terminal windows, to make it stay, just add these lines to your ~/.bash_profile

No comments: