Showing posts with label Ruby Multiple Versions. Show all posts
Showing posts with label Ruby Multiple Versions. Show all posts

Thursday, March 31, 2011

Getting `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError) while creating new rails application after installing pik gem

In my previous post "steps-to-install-pik-add-ruby-to-pik.html", described how to install pik on windows, adding ruby version to pik and switching between various ruby versions through pik.

After installing pik, added Ruby 1.9.2 and then switched to Ruby 1.9.2:

>pik 192
>pik list
   187: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
* 192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

When I checked rails version after switching Ruby version to 1.9.2, I got error.

>rails -v
'rails' is not recognized as an internal or external command,
operable program or batch file.

Tried to create new rails application, but again got error:
>rails new demos
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:861:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:255:in `activate'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems.rb:1204:in `gem'
        from C:/Ruby187/bin/rails:18:in `<main>'

To fix this problem, I installed rails gem in Ruby 1.9.2
>gem install rails

And then I checked rails version.
>rails -v
Rails 3.0.5

I was able to create new rails application. 
On my existing rails application which has already been updated to Rails -v 3.0.3, I ran 'bundle install' and it executed and installed the gems listed in Gemfile.

Steps to install pik, add ruby to pik list and switch between Ruby version

I use Pik to manage multiple versions of ruby on a Windows machine. Here are the steps to install pik:

Install the pik gem
> gem install pik
......
Successfully installed pik-0.2.8
1 gem installed

Then check path
>path
PATH=C:\Program Files\ImageMagick-6.6.4-Q16;C:\Program Files\ImageMagick-6.5.6-Q8;C:\Windows\system32;C:\Program Files\Git\bin;C:\Program Files\Git\cmd; C:\Ruby187\bin

Then Install pik to a location other than your ruby\bin dir. I used C:\pik

>pik_install C:\pik
Thank you for using pik.
Installing to C:\pik
...
pik is installed

It will install pik and will create a folder 'pik' in C:\ drive. You will get 'C:\pik'
Now add the variable 'C:\pik' in your 'Environmental Variables' path.

For steps to add path in 'Environmental Variables' or troubleshooting the setup of 'Environmental Variables', please see post "setting-path-cpik-in-environmental-variable"

Download Ruby 1.9.2 exe from http://rubyforge.org/frs/download.php/74298/rubyinstaller-1.9.2-p180.exe
Install and add the new Ruby version to pik registry.

>pik add C:\Ruby192\bin

You can check the List of all available Ruby versions added in pik, one with the '*' sign displays the default one:

>pik list
* 187: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
   192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]


>ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]


To switch to Ruby 1.9.2:

>pik 192
>pik list
   187: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
* 192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]



>ruby -v
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

To switch back to Ruby 1.8.7:
>pik 187

Its over and pik is successfully installed, now you know how to install pik, add ruby to pik list and switch between Ruby version

Pik & RVM, tools to manage multiple Ruby versions on Windows, OS X, Linux

I have a Rails application that I have upgraded from Rails 2.3.5 to Rails 3.0.3. Removed deprecations and made that application stable on Rails 3.0.3. And now, it was Ruby turn to be upgraded from
 - Ruby 1.8.7 to Ruby 1.9.2.

This Ruby Migration was really going to be a challenging one because of two reasons:
Firstly, My application is running on Windows as well as on Linux, Ubuntu, Mac.
Secondly, I need both Ruby versions, 1.8.7 and 1.9.2 for my application because I don't know how my application will behave with Ruby 1.9.2, what are the things that will break, so be on safer side  I want both versions.

My basic requirement was to be able to switch between Ruby versions easily so that rest of my work doesn't get impacted because of Ruby upgradation. I have heard of RVM (Ruby Version Manager) that makes it easy to install and switch between multiple Ruby versions on OS X and Linux.

But, sadly RVM cannot be used on Windows. Now what! To my rescue, came another gud tool, Pik.

Pik is a tool to manage multiple versions of ruby on Windows. It can be used from the Windows command line (cmd.exe), Windows PowerShell, or Git Bash. Very much similar to RVM.

In next few blogs, watch how to install Pik, upgrade Ruby version to 1.9.2 on Windows and challenges faced during upgradation.