bash 使用 Cygwin 运行 Ruby gems
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33125675/
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
Running Ruby gems with Cygwin
提问by lopert
I am using Cygwin with the cygwin'd version of ruby on Windows.
我在 Windows 上将 Cygwin 与 cygwin 的 ruby 版本一起使用。
$ 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 (gem install rspec) 后,我尝试运行基本 init 命令 (rspec --init) 以开始使用,但我收到一条 bash 命令未找到消息。
$ 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).
我猜这是因为我的 C:\cygwin64\bin 目录下没有“rspec”文件(因为有“ruby”、“irb”等文件,cygwin 在输入命令时必须查看这些文件)。
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.
查看我的 cygwin 目录,我可以看到“C:\cygwin64\home\username\.gem\ruby\gems\rspec-core-3.3.2\exe”下的 rspec“exe”文件。我认为这意味着只需将此文件添加到 cygwin 的路径即可,但我一直找不到一个很好的例子。理想情况下,该解决方案将处理这个 gem (rspec) 和所有未来的安装,而不必每次都对路径进行“硬编码”。
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.
看看我的“宝石环境”,安装的宝石似乎已经在我的“宝石路径”下。这似乎与 Cygwin 正在寻找的地方之间存在脱节。
$ 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:
我在搜索中发现的最接近的是另一个 StackOverflow 问题:
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.
但根据我对解决方案的理解,它将寻找扩展名为 .bat 的文件。在我的 cygwin 中运行它的一部分来测试它不会产生有用的结果。
Any tips on making cygwin line up with what I'm seeing in gem environment?
关于使 cygwin 与我在 gem 环境中看到的内容一致的任何提示?
回答by Fge
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
:
我的问题是,所有 ruby 可执行文件都存储在~/bin
. 中,而我的 cygwin 路径中没有设置它。因此,我更改了所有 ruby gem 及其可执行文件的位置~/.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.
重新安装 gem 后,从我开始一切正常。这会将所有 gem 可执行文件直接安装到/usr/bin
. 当涉及到多用户设置时,这肯定有点脏。
If you require a proper multi-user setup, the better way would be to adjust the PATH
to point to ~./bin
isntead.
如果您需要适当的多用户设置,更好的方法是将PATH
to 点调整为~./bin
istead。
Further readings:
进一步阅读:
回答by drkvogel
You could just add the following to your .bashrc
or similar:
您可以将以下内容添加到您的.bashrc
或类似内容中:
export PATH=$PATH:~/bin
and do source ~/.bashrc
to add it to the path immediately.
并source ~/.bashrc
立即将其添加到路径中。