我无法让 Ruby gem 在 macOS 上与 TextMate (TM) 和 chruby 一起正常工作。
大约六个月前在 2017 iMac 上全新安装 Mojave(现为 v10.14.4)。
尝试使用 Ruby-2.6.2,尽管已经安装了早期版本。系统 Ruby 是 v2.3.7
我最终在至少三个位置获得了宝石:
~/.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 和 GEM_PATH定义为
GEM_PATH 提供了可以找到 gem 的位置(可能有多个)。
GEM_HOME 是安装 gem 的地方(默认情况下)。
问题是当我在 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
第 19 行是require 'mini_exiftool'
mini_exiftool
在宝石列表中,但为什么会出错?
如果我使用系统 Ruby 运行脚本(采用默认值,在 TM 中没有设置任何内容)
脚本运行并输出以下输出:
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 中是可以的,但其他的可能不是。
谢谢你的帮助。
这篇文章是我之前发帖的简化版。我想我已经把问题归结了。