RubyGems + Cygwin: POSIX path not found by ruby.exe
I am a Ruby programmer on Windows who trys to switch from Win cmd to Cygwin, but cannot achieve to execute batch files of Ruby gems.
I already 开发者_JAVA技巧stuffed any bin directory into the Windows PATH
env. variable, including the Ruby bin where the executables are stored. Gems, however, are invoked by ruby.exe itself, which leads to the following problem with POSIX paths:
duddle@duddledan /cygdrive/c/Ruby/ruby-186-398/bin
$ gem -v
C:\Ruby\ruby-186-398\bin\ruby.exe: No such file or directory -- /cygdrive/c/Ruby/ruby-186-398/bin/gem (LoadError)
duddle@duddledan /cygdrive/c/Ruby/ruby-186-398/bin
$ ./gem --version
1.3.7
When calling e.g. ./gem
directly by specifying the path, it can be found and executed.
Any ideas?
Edit:
How to tell cygwin not to process batch files?
You can mix and match Cygwin with MingW32 Ruby if you are careful and there are good reasons for doing so. Cygwin provides a more fleshed out CLI environment than does MSYS but Cygwin's bundled Ruby is much slower than the MingW32 version. The trick is to alias all the RubyGem wrappers in your Cygwin .bashrc. Here is a snippet from mine.
alias gem='gem.bat'
alias rake='rake.bat'
alias erb='erb.bat'
alias irb='irb.bat'
alias rdoc='rdoc.bat'
alias ri='ri.bat'
alias rspec='rspec.bat'
alias cucumber='cucumber.bat'
alias bundle='bundle.bat'
The trick is to alias all .bat
files as Robert pointed out in his answer.
Adding a new alias to your .bashrc
or .zshrc
after every gem install
ain't fun though ...
Therefore i create these aliases automatically by scanning Ruby's bindir:
if [[ -n "$(which ruby 2>/dev/null)" ]]; then
RUBY_BIN=$(cygpath -u $(ruby -e 'puts RbConfig::CONFIG["bindir"]') | tr '\r' ' ')
for f in $(find ${RUBY_BIN} -regex ".*bat$"| xargs -n1 basename); do
alias ${f%.bat}=${f}
done
fi
You're trying to mix batch files which expect native paths with Cygwin, which completely dislike it.
When you call ./gem you're invoking the ruby script, but using the PATH
is invoking the batch file.
Either you tell cygwin not to process batch files (dunno how) or you use MSYS Bash if you want a replacement of cmd.exe, but don't mix Cygwin with native Ruby.
I've blogged about mixing and matching in the past:
http://blog.mmediasys.com/2008/10/27/handy-tip-dont-mix-one-click-installer-with-cygwin/
精彩评论