Posterous theme by Cory Watilo

Managing multiple Ruby environments with pik

In my last post, I talked about using git to distribute the same ruby environment from production to development in order to make sure the code that works in development is more assured of working in production as well.

However, this might normally constrain you to only using one ruby environment on your development machine (the production one), which is a real constraint. Especially when it comes to evaluating whether to upgrade to the latest Spree code, for example, you might need an entirely different environment. Using git to try to swap back and forth between two or more ruby environments is not a good solution, since you don't want your private ruby environment to pollute the repository, and you probably want the two (or more) to exist alongside each other for the long term.

Unix users have RVM to handle this. Pik is a Windows alternative endorsed by the RVM developers.

You can install pik by following the directions in this post. Pik can then switch between different installed ruby environments with a single shell command.

Normally, you may manage different ruby versions with pik. You install the Ruby versions as usual, side-by-side, by using something like the Ruby installer. Each environment will contain an entirely different set of gems, so you can install two different versions of rails, for example, without any conflict and without it touching your golden production environment.

You should probably only have one instance on your path at a time. Pik will manage this when you switch environments.

Once installed, you run a pik command to add them to your list of environments. You can even add two rubies of the same version. You'll get a warning and be asked for a short name since normally it collapses the version number into a short name, which would cause a conflict when using two rubies of the same version.

Use the pik add [location] command to add different ruby environments to the list of available ones.

Use pik switch [shortname] to switch to an alternate ruby environment. Use ruby -v and/or rails -v to check that your environment.

Use pik default to switch back to your default ruby environment.