Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Ruby gems with Cygwin

Tags:

bash

ruby

cygwin

I am using Cygwin with the cygwin'd version of ruby on Windows.

$ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-cygwin]

After successfully installing rspec (gem install rspec), I try running the basic init command (rspec --init) to get started, but I get a bash command not found message.

$ rspec --init
-bash: rspec: command not found

I'm guessing this is happening because there is no "rspec" file under my C:\cygwin64\bin directory (as there is "ruby","irb", etc. files that cygwin must look at when commands are typed into it).

Looking through my cygwin directories, I can see the rspec "exe" file under "C:\cygwin64\home\username\.gem\ruby\gems\rspec-core-3.3.2\exe". I think this means it is simply a matter of adding this file to cygwin's path, but I have not been able to find a good example of this. Ideally the solution would handle this gem (rspec) and all future installs without having to "hard-code" the path everytime.

Looking at my "gem environment", it seems like the installed gems are already under my "GEM PATHS". It seems like there's a disconnect between this and where Cygwin is looking.

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.7
  - RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x86_64-cygwin]
  - INSTALLATION DIRECTORY: /home/username/.gem/ruby
  - RUBY EXECUTABLE: /usr/bin/ruby.exe
  - EXECUTABLE DIRECTORY: /home/username/bin
  - SPEC CACHE DIRECTORY: /home/username/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-cygwin
  - GEM PATHS:
     - /home/username/.gem/ruby
     - /usr/share/gems
     - /usr/local/share/gems
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/bin
     - /usr/bin
     ...

The closest thing I found in my searching was another StackOverflow question here:

What version of ruby use with cygwin?

but from what I understand of the solution, it is going to look for files with the .bat extension. Running parts of it in my cygwin to test it out doesn't produce useful results.

Any tips on making cygwin line up with what I'm seeing in gem environment?

like image 957
lopert Avatar asked Oct 14 '15 12:10

lopert


2 Answers

Although my answer is a bit late in this, I figure it might help someone having the same problem.

The problem for me was, that the all ruby executables were stored in ~/bin., which wasn't set in my cygwin path. So I changed the location of all ruby gems and their executables in my ~/.gemrc:

gemhome: /usr/local/rubygems
gem: --bindir /usr/bin

After re-installing the gems, everything worked fine from me forward. This will install all gem executables directly into /usr/bin. This is for sure a bit dirty when it comes to multi-user setups.

If you require a proper multi-user setup, the better way would be to adjust the PATH to point to ~./bin isntead.

Further readings:

  • Default location of executables on Mailinglist
  • Change location of executables directory
like image 193
Fge Avatar answered Oct 25 '22 11:10

Fge


You could just add the following to your .bashrc or similar:

export PATH=$PATH:~/bin

and do source ~/.bashrc to add it to the path immediately.

like image 25
drkvogel Avatar answered Oct 25 '22 12:10

drkvogel