Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 843
crispy Avatar asked Sep 30 '10 13:09

crispy


2 Answers

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'
like image 80
Robert Wahler Avatar answered Oct 19 '22 18:10

Robert Wahler


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
like image 27
Nicolai Fröhlich Avatar answered Oct 19 '22 19:10

Nicolai Fröhlich