gem macOS 中具有 chruby 和 TextMate 首选项的位置

gem locations in macOS with chruby and TextMate preferences

我无法让 Ruby gems 在 macOS 上正确使用 TextMate (TM) 和 chruby。

大约六个月前,在 2017 iMac 上全新安装了 Mojave(现在是 v10.14.4)。

尝试使用Ruby-2.6.2,虽然已经安装了更早的版本。系统 Ruby 是 v2.3.7

我至少在三个位置得到了 gem:

~/.rubies/ruby-2.6.2/lib/ruby/gems/2.6.0/gems/
~/.gem/ruby/2.6.2/gems/
/Library/Ruby/Gems/2.3.0/gems/

TextMate 依赖其 gem 和 Ruby 位置的首选项。作为开始,我有以下内容: GEM_HOME 未设置,因为我不明白为什么需要它,尽管我经常阅读以如图所示或类似方式设置它。 GEM_HOME and GEM_PATH 定义为

GEM_PATH 提供可以找到 gem 的位置(可能有几个)。

GEM_HOME 是安装 gems 的地方(默认)。

问题是我在TM运行这个脚本时(报错后不包含)

#!/usr/bin/env ruby
system ('gem env') # for debugging
puts "\nGem.path: #{Gem.path}"
puts "\ngem list:"
system ('gem list') # for debugging 
require 'fileutils'
include FileUtils
require 'find'
require 'yaml'
require "time"
require 'irb'
require 'mini_exiftool'

结果是:

Running “PhotoName-GPScoord.rb”…
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-darwin18]
Theme:  
RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.3
  - RUBY VERSION: 2.3.7 (2018-03-28 patchlevel 456) [universal.x86_64-darwin18]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.3.0
  - USER INSTALLATION DIRECTORY: /Users/gscar/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /usr/bin
  - SPEC CACHE DIRECTORY: /Users/gscar/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-18
  - GEM PATHS:
     - /Library/Ruby/Gems/2.3.0
     - /Users/gscar
     - /.rubies/ruby-2.6.2/lib/ruby/gems/2.6.0
     - /.gem/ruby/2.6.2/gems/
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-document"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /Users/gscar/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/bin
     - /usr/local/bin
     - /usr/texbin
     - /opt/local/bin

Gem.path: ["/Users/gscar", "/.rubies/ruby-2.6.2/lib/ruby/gems/2.6.0", "/.gem/ruby/2.6.2/gems/", "/Users/gscar/.rubies/ruby-2.6.2/lib/ruby/gems/2.6.0"]

gem list:
<about 100 gems>
mimemagic (0.3.3)
mini_exiftool (2.9.0)
mini_magick (4.6.1)
<about 20 gems>

LoadError: cannot load such file — mini_exiftool

method require  in kernel_require.rb at line 54
method require  in kernel_require.rb at line 54
method <main>   in PhotoName-GPScoord.rb at line 19
  copy output 

TextMate 将其放在输出的右上角

第 19 行是 require 'mini_exiftool'

mini_exiftool在gem列表中,但为什么会报错?

如果我运行使用系统Ruby的脚本(采用默认值,TM 中没有任何设置)

脚本 运行s 具有以下输出:

Running “PhotoName-GPScoord.rb”…
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
Theme:  
RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.3
  - RUBY VERSION: 2.3.7 (2018-03-28 patchlevel 456) [universal.x86_64-darwin18]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.3.0
  - USER INSTALLATION DIRECTORY: /Users/gscar/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /usr/bin
  - SPEC CACHE DIRECTORY: /Users/gscar/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-18
  - GEM PATHS:
     - /Library/Ruby/Gems/2.3.0
     - /Users/gscar/.gem/ruby/2.3.0
     - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-document"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /Users/gscar/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/bin

Gem.path: ["/Users/gscar/.gem/ruby/2.3.0", "/Library/Ruby/Gems/2.3.0", "/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0"]

gem list:

<long list of gems including mini_exiftool (2.9.0)>

此特定脚本适用于 2.3.7,但其他脚本可能不适用。

感谢您的帮助。

此贴是 earlier posting from me 的简化版。我想我已经把问题归结了。

GEM_HOMEGEM_PATH 更改为 $HOME/.gem/ruby/2.6.2:$HOME/.rubies/ruby-2.6.2/lib/ruby/gems/2.6.0 基于从终端 运行 时显示的变量中复制这些变量。卢的评论让我更加认真地审视了所报道的内容。基本上我在第二条路径(冒号之后)中缺少 $HOME/ 。我已经摆弄了几个月