开发者

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

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.

I开发者_JAVA技巧 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.

What is the best way to go about this?


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

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

Path=C:\Path\To\Git\1.7.1\cmd

If not, add it in your session:

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

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

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

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


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

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.

Step by step for 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

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


  • 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 Path variable, under System variables.

  • Restart shell.

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


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.


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

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

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

I'm using a Windows 7 machine.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜