简体   繁体   中英

How do I make ruby on OSX read the correct Gems

I am running OSX High Sierra.

I have a ruby script I'm attempting to run on OSX (it's an Avid validation tool, but I don't think that matters).

When I run it, I get the following output ( added the code to print the version and the gem path)

MacBook-Pro:DTT jon$ ./run_test.command -h -v
-----
Ruby Version : 2.5.0
Gem Path : 
/Users/jon/.gem/ruby/2.5.0
/Users/jon/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0
-----
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- curses (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/jon/Downloads/AAX_Tools_DSH_0p2p1x753_2/DTT/sources/DishTestTool.rb:21:in `<top (required)>'
    from /Users/jon/Downloads/AAX_Tools_DSH_0p2p1x753_2/DTT/sources/bin/runsuite.rb:82:in `require_relative'
    from /Users/jon/Downloads/AAX_Tools_DSH_0p2p1x753_2/DTT/sources/bin/runsuite.rb:82:in `<main>'

Note that it appears to be reading gems from version 2.3, but I am actually running 2.5.0

and if I do gem env, there is no sign of that 2.3 folder

MacBook-Pro:DTT jon$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.6
  - RUBY VERSION: 2.5.0 (2017-12-25 patchlevel 0) [x86_64-darwin17]
  - INSTALLATION DIRECTORY: /Users/jon/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0
  - USER INSTALLATION DIRECTORY: /Users/jon/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /Users/jon/.rbenv/versions/2.5.0/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/jon/.rbenv/versions/2.5.0/bin
  - SPEC CACHE DIRECTORY: /Users/jon/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/jon/.rbenv/versions/2.5.0/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-17
  - GEM PATHS:
     - /Users/jon/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0
     - /Users/jon/.gem/ruby/2.5.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/jon/.rbenv/versions/2.5.0/bin
     - /usr/local/Cellar/rbenv/1.1.1/libexec
     - /Users/jon/.rbenv/shims
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /opt/local/bin
     - /opt/X11/bin

I've tried installing ruby with rvm, then uninstalled it, removed rvm, installed it again with rbenv. Installing and updating gems (curses in particular), etc etc (I'm a newbie with ruby and moderately familiar with the workings of Unix systems, but no systems guru), but all to no avail.

Does anybody know how I get ruby to read the correct gems?

--------------- Edit ---------------- I've discovered cause of the issue The ruby script run_test.command called another ruby script, with the line

system("#{ruby} \"#{runsuite_path.realpath}\" #{args}")

Where, crucially

ruby = '/usr/bin/ruby'

For some reason, updating ruby does not change the version of ruby executed with /usr/bin/ruby

changing that line to

ruby = '/usr/bin/env ruby'

Seems to fix the issue

Which begs two questions. Why is /usr/bin/ruby not changed to reflect the update, and can I change it manually without issues?

The ruby binary that is found at /usr/bin/ruby is the version of Ruby installed by MacOS and should be left alone. Homebrew, Chruby, RVM & RBEnv all will install rubies in different locations away from the base so that they don't overwrite it or change it. This is expected behaviour, as you don't know what could be depending on the system ruby, or what has been natively compiled against it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM