Since Rails3 is quite popular right now, many programmers move their projects to this version. So did I However, because of some major bugs in Ruby 1.8.7, Rails3 needs Ruby >=1.9.1. The problem is that I still have to maintain some Rails 2.3.5 projects…
There is a solution: Ruby Version Manager (RVM)… but not for windows 😛 For the latter, you should use PIK gem https://github.com/vertiginous/pik. The installation is pretty easy, just follow the tutorial at github repo step by step.
PROBLEM
So install PIK, add all ruby versions you want to, use the one you need. But well, life is not that easy… Supposing you’ve got some more complicated gem dependencies in your gemfile, when you try to run:
rake db:migrate
you will probably see the message like below:
There was an error. Error - can't dup NilClass /gemname/
or, in case you use sqlite3:
Unknown method sqlite3_backup_finish in sqlite3.dll.
SOLUTION
1. Set gem_home for the choosen ruby version. Probably the path to install gems isn’t set to unique for every Ruby version you’ve installed. This may be highly confusing and cause some errors if you use different gem versions for Rails 2.3.x and Rails3 (which is the case in 99% of cases).
- Supposing you work on Ruby 1.9.2, you type: pik use 192.
- Then you can check where is current working dir: which ruby or which rails.
- Go to c:/Users/username/.pik/config.yml.
- Edit the proper line in YAML file adding the following lines to the chosen Ruby version
:gem_home: !ruby/object:Pathname path: c:/users/greg/.pik/rubies/Ruby-192-p180
So that the whole version definifion will look like:
"192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]": :gem_home: !ruby/object:Pathname path: c:/users/greg/.pik/rubies/Ruby-192-p180 :path: !ruby/object:Pathname path: C:/Users/Greg/.pik/rubies/Ruby-192-p180/bin
Mind the spaces and tabs!
2. SQLite 3 for Windows needs some additional libraries. You can find them at http://www.sqlite.org/download.html The solution is simple: download the sqlite3.dll and sqlite3.exe and copy it to your Ruby bin directiory, i.e. C:/Users/Greg/.pik/rubies/Ruby-192-p180/bin
I hope this was helpful and saved you some time of your life 😉