如何在 Windows 上的一处运行 Ruby 和 GIT 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3426347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:00:28  来源:igfitidea点击:

How to run Ruby and GIT commands in one place on Windows

ruby-on-railsrubygit

提问by Joseph U.

I have Ruby and GIT installed on my windows box. To run GIT commands I am utilizing the GIT Bash. To run Ruby commands I am using the command line.

我的 Windows 机器上安装了 Ruby 和 GIT。为了运行 GIT 命令,我使用了 GIT Bash。要运行 Ruby 命令,我使用命令行。

I have not been successful running GIT commands from the CMD line nor can I seem to run Ruby commands from inside the GIT Bash. I would love to be able to run commands for both GIT and Ruby from the GIT Bash (ideal) or at the least from the CMD line.

我没有成功地从 CMD 行运行 GIT 命令,我似乎也无法从 GIT Bash 内部运行 Ruby 命令。我希望能够从 GIT Bash(理想)或至少从 CMD 行运行 GIT 和 Ruby 的命令。

What is the best way to go about this?

解决这个问题的最佳方法是什么?

回答by VonC

I run git commands from the CMD session all the time.

我一直从 CMD 会话运行 git 命令。

Make sure your PATHenvironment variable includes the 'cmd' directory from a msysgit distro:

确保您的PATH环境变量包含cmd来自 msysgit 发行版的“ ”目录:

Path=C:\Path\To\Git.7.1\cmd

If not, add it in your session:

如果没有,请将其添加到您的会话中:

set PATH=%PATH%;C:\Path\To\Git.7.1\cmd

and you are done. Git andRuby commands in your CMD shell.

你就完成了。CMD shell 中的GitRuby 命令。

The reverse (Ruby commands) is possible in a Git bash, by adding to the PATHa value like /c/path/to/Ruby/186-27/bin

反向(Ruby 命令)在 Git bash 中是可能的,通过添加到PATHa 值,如/c/path/to/Ruby/186-27/bin

http://img842.i_mageshack.us/img842/8749/gitbashruby.png

http://img842.i_mageshack.us/img842/8749/gitbashruby.png

回答by Rots

To elaborate on VonC's answer of making Ruby available in Git-Bash.

详细说明 VonC 在 Git-Bash 中提供 Ruby 的答案。

All you have to do is add the path to your Ruby bin folder in your windows environment variables. It doesn't have to be in the format /c/path/to/ruby, it can be C:\Ruby193\bin.

您所要做的就是在 Windows 环境变量中添加 Ruby bin 文件夹的路径。它不必采用 /c/path/to/ruby 格式,它可以是 C:\Ruby193\bin。

Step by step for Windows 7:

Windows 7 的分步说明:

  1. Start
  2. Search programs and files (default textbox after hitting the Start icon), Search for 'environment'
  3. Select 'edit the system environment variables'
  4. Click 'Environment Variables' (bottom right of the form)
  5. Add to the 'System Variables' 'PATH' the following ';C:\Ruby193\bin' (without the single quotes)
  6. Restart your shell
  1. 开始
  2. 搜索程序和文件(点击开始图标后的默认文本框),搜索“环境”
  3. 选择“编辑系统环境变量”
  4. 单击“环境变量”(表单右下角)
  5. 将以下 ';C:\Ruby193\bin' 添加到 'System Variables' 'PATH' (不带单引号)
  6. 重启你的外壳

Make sure to close your git-bash shell and restart it to pick up the new environment variable.

确保关闭 git-bash shell 并重新启动它以获取新的环境变量。

回答by timofey.com

  • Go to My Computer -> Properties -> Advanced system settings -> Environment Variables

  • Add a New System variable. Variable name = RUBY_BIN. Variable value = C:\Ruby193\bin(path may vary).

  • Add a New System variable. Variable name = MSYSGIT_BIN. Variable value = C:\msysgit\bin(path may vary).

  • Append ;%RUBY_BIN%;%MSYSGIT_BIN%to Pathvariable, under System variables.

  • Restart shell.

  • 转到我的电脑 -> 属性 -> 高级系统设置 -> 环境变量

  • 添加一个新的系统变量。变量名 = RUBY_BIN。变量值 = C:\Ruby193\bin(路径可能不同)。

  • 添加一个新的系统变量。变量名 = MSYSGIT_BIN。变量值 = C:\msysgit\bin(路径可能不同)。

  • ;%RUBY_BIN%;%MSYSGIT_BIN%附加到系统变量下的路径变量。

  • 重新启动外壳。

This will allow you to run ruby, git or sh (Git Bash) commands from Command Prompt, as well as Ruby from Git Bash.

这将允许您从命令提示符运行 ruby​​、git 或 sh(Git Bash)命令,以及从 Git Bash 运行 Ruby。

回答by Jannaee

The combined answer for VonC and Rots helped me to achieve the desired results.

VonC 和 Rots 的组合答案帮助我达到了预期的结果。

However, since I was not familiar with editing environment variables, I must have accidentally overwritten the path for my nodejs files.

然而,由于我不熟悉编辑环境变量,我一定不小心覆盖了我的 nodejs 文件的路径。

As a result my solution included adding the ruby path and the nodejs path to my user variables instead of the system.

因此,我的解决方案包括将 ruby​​ 路径和 nodejs 路径添加到我的用户变量而不是系统。

I'm using a Windows 7 machine.

我正在使用 Windows 7 机器。

回答by Muhammad Nabeel

while installing ruby installer, select the option "Add ruby executables to your path" . Then all git/ruby commands will run from git bash.

在安装 ruby​​ 安装程序时,选择“将 ruby​​ 可执行文件添加到您的路径”​​选项。然后所有 git/ruby 命令将从 git bash 运行。

回答by Karl

My personal setup uses msysgit and tortoisegit. I've found that using TortoiseGit's Pageant manager for the keys lets me use everything from any command line, including powershell. The only annoyance is I have to have pageant running with the keys added, which seem to clear on every reboot. Fortunately I don't reboot often.

我的个人设置使用 msysgit 和 tortoisegit。我发现使用 TortoiseGit 的 Pageant 管理器作为键可以让我从任何命令行使用所有东西,包括 powershell。唯一的烦恼是我必须在添加密钥的情况下运行选美,这似乎在每次重新启动时都会清除。幸运的是我不经常重启。