Ruby version manager for Windows
Ruby version manager is a great tool that allows you to easily have multiple versions of Ruby. For Unix-based environment, there is RVM and for Windows we have Pik. This post will take you to have a quick look on Pik.
Installation
When writing this post I am using ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-mingw32] on Windows 7. You can use Pik from the Windows command line, Windows PowerShell, or Git Bash. Here I am using the command line. You can install pik via rubygems, or the Windows installer, or you can update pik with pik. Let us install pik using rubygems
gem install pikIf the installation gone smooth, you should see
Successfully installed pik-0.2.8 1 gem installedAfter pik is installed now you want to use
pik_install script to install the pik executable. You must install pik to a location in your path, but not in your Ruby bin directory. I add C:\bin to my path, so I run
pik_install C:\binthen you should see
pik is installed if you want to use pik with git bash, add the following line to your ~/.bashrc: [[ -s $USERPROFILE/.pik/.pikrc ]] && source $USERPROFILE/.pik/.pikrcUpdate: the command prompt from which you run
pik has to be started using run as Administrator (if it’s Windows 7). Pik is modifying %PATH% environment variable and Windows 7 would silently not let it do so if not enough user privileges.
Now for the first time run
pikand pik will print some message and at the top of the message you should see that pik was adding your current Ruby version
** Adding: 191: ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-mingw32] Located at: C:\Ruby191\bin ...
Usage
To list all available pik commands, simply run
pik help commandsIn this post I will show you how to add and use another Ruby version and how to handle gem
How to add and use another Ruby version
Let’s start with installing another Ruby version, I am installing Ruby 1.8.7 using rubyinstaller-1.8.7-p299.exe from RubyInstaller for Windows. During the installation, I was not mark the “Add Ruby executables to your PATH” option checked. After the install was done, I run
ruby -vand see that Windows still using 1.9.1 version instead of 1.8.7. Now let’s add 1.8.7 to pik
pik add C:\Ruby187\bin ** Adding: 187: ruby 1.8.7 (2010-06-23 patchlevel 299) [i386-mingw32] Located at: C:\Ruby187\binNow run
pik listto list available Ruby versions
187: ruby 1.8.7 (2010-06-23 patchlevel 299) [i386-mingw32] * 191: ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-mingw32]the * before 191 means that we are using Ruby 1.9.1 at the moment. Now let’s switch to Ruby 1.8.7
pik use 187and then when you run "pik list" or "ruby -v" you will notice that we are using Ruby 1.8.7 instead of 1.9.1
How to handle gem
Before I install pik, I already install some gems (on Ruby 1.9.1) and when I switch to 1.8.7, gem list doesn’t recognize any gem installed previously (since it’s in different directory). Using pik you can install gem that will available on every Ruby versions on your environment
pik gem install win32consolenow you should have win32console gem available on both versions or Ruby
ruby 1.8.7 (2010-06-23 patchlevel 299) [i386-mingw32] Successfully installed win32console-1.3.0-x86-mingw32 1 gem installed ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-mingw32] Successfully installed win32console-1.3.0-x86-mingw32 1 gem installedWell, there you go, we’re now set up with multiple Rubies, just imagine the fun we can have :)
