Posts Tagged ‘renaming’

Managing several Ruby versions and Gem collections on Windows with Pik

Tuesday, April 12th, 2011

If you have several versions and releases of Ruby (e.g. 187-p330, –p334, 1.9.2…) each with their own set of collections of gems for a specific app, then Pik becomes a bit cumbersome to select and manage your Ruby versions – there’s no command to “rename” a Ruby version to a for you memorable name (such as the name for the application linked to the ruby install).

  $ pik list

  186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
  187-ref-r187-p330: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
* 187: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
  187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
  192-192-rubies-refinery: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
  192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

Now there’s also a way to do that manually: just edit the config.yml file in your C:\Users\Pascal\.pik\ folder:

---
"186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]":
  :path: !ruby/object:Pathname
    path: C:/Ruby/bin
"187-ref-r187-p330: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p330/bin
"187: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/ruby187/bin
"187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p334/bin
"192-192-rubies-refinery: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-192-p180/bin
"192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/Ruby192/bin
--- {}


Becomes (by changing the “logical names” before the colon to something more meaningful):

---
"Default-186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]":
  :path: !ruby/object:Pathname
    path: C:/Ruby/bin
"RefineryGemset-187-p330: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p330/bin
"Default-187: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/ruby187/bin
"Clean-187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p334/bin
"RefineryGemset-192-p189: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-192-p180/bin
"Default-192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/Ruby192/bin
--- {}

And now listing and selecting (with Pik use…) the right version is a lot easier:

  $ pik list
  Clean-187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
  Default-186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
* Default-187: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
  Default-192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
  RefineryGemset-187-p330: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
  RefineryGemset-192-p189: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

What you can also do now, is manually copying a base Ruby+gems collections when you start a new app, e.g. copy C:\Users\Pascal\.pik\rubies\Ruby-187-p334 to C:\Users\Pascal\.pik\rubies\Ruby-187-p334-Refinery and add in the config.yml:

"Newapp-187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]":
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p334-Refinery/bin

BTW: don’t forget to also add the path to the new Ruby version to your Devkit/config.yml file and to run ruby dk.rb install if you want to use native extensions.