Hacking at Relevance: Agile Development, Consulting and Training

Friday, February 20

Easily switch between Ruby 1.8.6 and 1.9.1

NOTE: I don't keep Ruby Switcher updated anymore. Use RVM instead.

Chad mentioned that he'd gotten ruby 1.9.1 and 1.8.6 side by side on his workstation (his code for this is in his awesome spicy-config repo).

I took some time this morning to get a similar setup working. Now, on my prompt, I type, use_ruby_186 or use_ruby_191 to go back and forth between the Ruby 1.8.6 shipped with Leopard and a self-compiled install of ruby 1.9.1.

Steps for you to get there:

  1. Compile and install ruby 1.9.1:
    mkdir -p ~/tmp
    cd ~/tmp
    curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.gz
    tar xzf ruby-1.9.1-p0.tar.gz
    cd ruby-1.9.1-p0
    ./configure --prefix=$HOME/.ruby_versions/ruby_191
    make
    make install
    
  2. Install the ruby switcher:
    curl -L http://github.com/relevance/etc/tree/master%2Fbash%2Fruby_switcher.sh?raw=true?raw=true > ~/ruby_switcher.sh
    echo "source ~/ruby_switcher.sh" >> ~/.bash_profile
    

Note that I use ~/.gem for my gems. If you don't do that, you'll have to modify the switcher to specify your GEM_HOME. Type gem env and look for GEM PATHS to figure out what you should set it to.

4 comments:

elliottcable said...

I just install both side by side: http://tr.im/gFJN?github

rio517 said...

I created a dedicated repo for the ruby_switcher.

http://github.com/Rio517/ruby_switcher

-Mario

human mathematics said...

Are there any guarantees with the switching shell that other gems and other stuff won't be messed up? I just spent two hours trying random google results to get RSRuby to work in Ruby 1.8 (Ubuntu 10.04).

muness said...

human mathematics: the script switches Gem directories. However, I suggest you use RVM instead. It's more complicated, but what the community has settled on for installing and switching between multiple rubies.