My work requires Ruby 1.8.7 and Rails 2.3.8 so the default Ruby 1.8.7 on Mac OS X does the job well. However I am itching to try out the Rails 3.0.0 and Ruby 1.9.2. But I don’t want to mess up with my current setup, so how could I have two version of Ruby running that do not bitch at each other?
Well, this tutorial I will show you how to install mutiple instances of Ruby w/o PATH hassles. Thanks to ‘rvm’, doing this could not be easier. ‘rvm’ stands for Ruby Versioning Manager, is a script that help you capsulate many Ruby version.
Prerequisites
First you need to make sure your system met the requirements . I am using a Mac, so I need XCode 3.2 installed (the Download version one, not the DVD version because it has some bugs). And you also need to have ‘git’ installed too.
Installation
Grab the ‘rvm’ from its github and run the installation script:
mkdir -p ~/.rvm/src/ && cd ~/.rvm/src && rm -rf ./rvm/ && git clone --depth 1 git://github.com/wayneeseguin/rvm.git && cd rvm && ./install
Once finished, you should see output telling you to append a short snippet to the .bashrc and .bash_profile file. On my Mac, I have to append the following snippet into ~/.bashrc and ~/.bash_profile
echo "if [[ -s /Users/MAC/.rvm/scripts/rvm ]] ; then source /Users/MAC/.rvm/scripts/rvm ; fi" >> ~/.bashrc echo "source ~/.bashrc" >> ~/.bash_profile
Please replace the snippet in your output in the text after the ‘echo’ command.
Close your Terminal and open it again to reload the bashrc. And you can start play with ‘rvm’.
rvm version
would give you
rvm 1.6.32 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]
Next is to install ruby 1.8.7 and ruby 1.9.2
rvm install 1.8.7 -C --enable-shared,--enable-pthread rvm install 1.9.2 -C --enable-shared,--enable-pthread
Once finishing the above step, you can verify if it’s successful by
rvm list
you should see ruby1.8.7 and ruby1.9.2 in the list
rvm Rubies ruby-1.8.7-p352 [ x86_64 ] ruby-1.9.2-p290 [ x86_64 ] Default Ruby (for new shells) ruby-1.8.7-p299 [ x86_64 ] System Ruby system [ x86_64 i386 ppc ]
Usage
To use an instance for example ruby 1.8.7, invoke command
rvm use 1.8.7
or for 1.9.2
rvm use 1.9.2
if you want to set 1.8.7 the default
rvm use 1.8.7 --default
or with 1.9.2
rvm use 1.9.2 --default
You can verify the instance info with
rvm info
Know issues
Ruby 1.8.7 skips building ri and rdoc. The workaround is specify:
rvm docs generate-ri
OR to generate ri doc from source:
cd $rvm_path/src/ruby-1.8.7-p352 make install-all
linecache19 and ruby-debug19 are not installed due to missing Ruby headers. Here is how to fix:
gem install ruby-debug19 -- --with-ruby-include=$rvm_path/src/ruby-1.9.2-p290 gem install linecache19 -- --with-ruby-include=$rvm_path/src/ruby-1.9.2-p290
Nice post. It helped me a lot.
Regarding the fact that building ri is skipped…
You can also be specific and use
$ rvm docs generate-ri