bash RubyGems + Cygwin:ruby.exe 找不到 POSIX 路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3831131/
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
RubyGems + Cygwin: POSIX path not found by ruby.exe
提问by crispy
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.
我是 Windows 上的 Ruby 程序员,他尝试从 Win cmd 切换到 Cygwin,但无法执行 Ruby gems 的批处理文件。
I already stuffed any bin directory into the Windows PATHenv. 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:
我已经把任何 bin 目录塞进了 Windows 环境中PATH。变量,包括存储可执行文件的 Ruby bin。但是,gems 是由 ruby.exe 本身调用的,这会导致 POSIX 路径出现以下问题:
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. ./gemdirectly by specifying the path, it can be found and executed.
eg./gem直接指定路径调用时,可以找到并执行。
Any ideas?
有任何想法吗?
Edit:
编辑:
How to tell cygwin not to process batch files?
如何告诉 cygwin 不处理批处理文件?
采纳答案by Luis Lavena
You're trying to mix batch files which expect native paths with Cygwin, which completely dislike it.
您正在尝试将需要本机路径的批处理文件与 Cygwin 混合,后者完全不喜欢它。
When you call ./gem you're invoking the ruby script, but using the PATHis invoking the batch file.
当您调用 ./gem 时,您正在调用 ruby 脚本,但使用PATH正在调用批处理文件。
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.
您要么告诉 cygwin 不要处理批处理文件(不知道如何处理),要么如果您想替换 cmd.exe,则使用 MSYS Bash,但不要将 Cygwin 与本机 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/
http://blog.mmediasys.com/2008/10/27/handy-tip-dont-mix-one-click-installer-with-cygwin/
回答by Robert Wahler
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.
如果您小心并且有充分的理由,您可以将 Cygwin 与 MingW32 Ruby 混合搭配。Cygwin 提供了比 MSYS 更充实的 CLI 环境,但 Cygwin 的捆绑 Ruby 比 MingW32 版本慢得多。诀窍是在 Cygwin .bashrc 中为所有 RubyGem 包装器设置别名。这是我的一个片段。
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'
回答by Nicolai Fr?hlich
The trick is to alias all .batfiles as Robert pointed out in his answer.
.bat正如罗伯特在回答中指出的那样,诀窍是为所有文件设置别名。
Adding a new alias to your .bashrcor .zshrcafter every gem installain't fun though ...
为您的.bashrc或.zshrc之后添加新别名gem install并不有趣...
Therefore i create these aliases automaticallyby scanning Ruby's bindir:
因此,我通过扫描 Ruby 的 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

