如何在 Windows 上的 Git Bash 中使用 Pik for Ruby?

发布于 2024-09-29 05:37:53 字数 703 浏览 3 评论 0原文

我在 Windows 上运行多个版本的 Ruby(和 Rails),并使用 Pik 在它们之间切换。在命令行,我可以调用

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

以获取可用的 ruby​​ 版本列表,并用于

> pik 192

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

使 ruby​​ 1.9.2 成为活动版本:

我无法在中执行相同的操作>git bash

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

并且ruby的版本仍然是1.8.6

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

git bash似乎看不到pik的路径。有没有办法改变 git bash 中的路径,或者有其他方法在 git bash 中运行 pik 吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

银河中√捞星星 2024-10-06 05:37:53

就目前而言,最后一个答案是正确的。但是,在 Windows 系统上,$USERPROFILE 环境变量设置为:C:\Documents and Settings\username。

路径中的空格会导致命令解释不正确。这更好:

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

请注意上面代码片段中路径周围的引号。

此外,您的 .bashrc 文件(或 .bash_profile 文件)应位于 USERPROFILE 环境变量指定的目录中,例如 - C:\Documents and Settings\username。

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.

别再吹冷风 2024-10-06 05:37:53

我必须编辑 .bash_profile 和 .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"
} 

仅当路径中有空格(如“程序文件”)时才需要在路径周围加上引号。

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").

少年亿悲伤 2024-10-06 05:37:53

请确保您安装了最新版本的 Pik (0.2.8)。在 Git Bash 下打开您的用户配置文件 .bash_profile 或类似文件,并确保它包含以下代码:

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

从那里您应该能够从 Git Bash 终端调用 pik。

希望有帮助

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文