7

I'm running multiple versions of Ruby (and Rails) on Windows and use Pik to switch between them. At the command line, I'm able to call

> pik list
186: ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
192: ruby 1.9.2p0 (2010-08-18) [i386-mingw32]

to get a list of ruby versions available, and use

> pik 192

> ruby -v
ruby 1.9.2p0 (2010-08-18) [i386-mingw32]

to make ruby 1.9.2 the active version:

I am not able to do the same in git bash:

 $ pik list
 sh.exe": pik: command not found

and the version of ruby is still 1.8.6

$ ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

It seems like git bash can't see the path to pik. Is there a way to alter the path within git bash or is there another way to run pik in git bash?

y0mbo
  • 4,582
  • 6
  • 41
  • 45

3 Answers3

10

The last answer is correct as far as it goes. However, on Windows systems the $USERPROFILE environment variable is set to something like: C:\Documents and Settings\username.

The spaces in the path cause the command to be interpreted improperly. This is better:

[[ -s "$USERPROFILE/.pik/.pikrc" ]] && source "$USERPROFILE/.pik/.pikrc"

Note the quotes around the paths in the code snippet above.

Additionally, your .bashrc file (or .bash_profile file) should be located within the directory specified by the USERPROFILE environment variable, e.g. - C:\Documents and Settings\username.

David Keener
  • 520
  • 6
  • 7
  • Also if you install Pik on a different drive (e.g. D:), you also need to edit the .pikrc file located under the .pik forlder under your user profile so that the pik_path points to the right drive. E.g.: pik_path=d:/pik – Philippe Monnet Sep 24 '11 at 16:05
  • Also if you install 1.9.2 separately using the Windows installer, you will need to edit the .pik/config.yml and add a gem_home setting pointing to the 1.9.2 gem home: :gem_home: !ruby/object:Pathname path: c:/Ruby192/lib/ruby/gems/1.9.1 – Philippe Monnet Sep 24 '11 at 17:21
  • 1
    Ok so I ended up creating a Gist for the 3 key changes needed: https://gist.github.com/1239600 – Philippe Monnet Sep 24 '11 at 17:34
3

I had to edit .bash_profile and .pikrc

.bash_profile:

[[ -s "$USERPROFILE/.pik/.pikrc" ]] && source "$USERPROFILE/.pik/.pikrc"

.pikrc

#!/bin/sh
pik_path="/c/Program Files/pik"

function pik  {
  "$pik_path/pik_runner.exe" pik.sh $@
  [[ -s "$USERPROFILE/.pik/pik.sh" ]] && source "$USERPROFILE/.pik/pik.sh"
} 

Having quotes around the paths is only necessary if you have spaces in the path (like "Program Files").

Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244
2

Please ensure you have the latest version of Pik installed (0.2.8), with it. open your user profile .bash_profile or similar under Git Bash and ensure it contains the following code:

[[ -s $USERPROFILE/.pik/.pikrc ]] && source $USERPROFILE/.pik/.pikrc

From there you should be able to invoke pik from the Git Bash terminal.

Hope that helps

Luis Lavena
  • 10,348
  • 1
  • 37
  • 39
  • not having quotes around `source $USERPROFILE/.pik/.pikrc` gave me trouble. So `"source $USERPROFILE/.pik/.pikrc"` fixed those... – goliatone Dec 07 '11 at 15:49