在Mac OS上设置Ruby Gems

时间:2017-02-18 00:24:51

标签: ruby macos rubygems

我试图在我的Mac OSX El Capitan上安装ruby,以便在非标准版本中安装宝石" location,我希望自己在目录/opt/Ruby/gems中安装所有宝石相关的内容。

已经安装了Ruby和gem:

> which gem
/usr/bin/gem
> which ruby 
/usr/bin/ruby

当我尝试安装Jekyll时,一切似乎都运行良好,Jekyll及其依赖项安装在/opt/Ruby/gems中(此目录已经在$ PATH中):

> ls -l /opt/Ruby/gems/bin/
total 64
-rwxr-xr-x  1 pmca  wheel  508 18 Feb 00:11 jekyll*
-rwxr-xr-x  1 pmca  wheel  516 18 Feb 00:11 kramdown*
-rwxr-xr-x  1 pmca  wheel  508 18 Feb 00:11 listen*
-rwxr-xr-x  1 pmca  wheel  506 18 Feb 00:11 rougify*
-rwxr-xr-x  1 pmca  wheel  520 18 Feb 00:11 safe_yaml*
-rwxr-xr-x  1 pmca  wheel  500 18 Feb 00:11 sass*
-rwxr-xr-x  1 pmca  wheel  508 18 Feb 00:11 sass-convert*
-rwxr-xr-x  1 pmca  wheel  500 18 Feb 00:11 scss*

然而,当我尝试运行Jekyll时,我收到以下错误:

> jekyll -h
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'jekyll' (>= 0) among 12 total gem(s) (Gem::LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem'
    from /opt/Ruby/gems/bin/jekyll:22:in `<main>'

如果我尝试运行与Jekyll一起安装的其他宝石,也会发生同样的情况,因此它应该是我必须具有宝石的配置,但我无法知道问题出在哪里。当我运行gem environment --debug时,事情看起来很好(对我来说......):

> gem environment --debug
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14.1
  - RUBY VERSION: 2.0.0 (2015-12-16 patchlevel 648) [universal.x86_64-darwin15]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-15
  - GEM PATHS:
     - /Library/Ruby/Gems/2.0.0
     - /opt/Ruby/gems
     - /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => true
     - :bulk_threshold => 1000
     - :sources => ["https://rubygems.org/"]
     - "install" => "--install-dir /opt/Ruby/gems"
     - "gempath" => ["/opt/Ruby/gems", "/Library/Ruby/Gems/2.0.0", "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0"]
  - REMOTE SOURCES:
     - https://rubygems.org/

.gemrc文件如下所示:

---
:backtrace: true
:bulk_threshold: 1000
:sources:
- https://rubygems.org/
:update_sources: true
:verbose: true
install: --install-dir /opt/Ruby/gems
gempath:
- /opt/Ruby/gems
- /Library/Ruby/Gems/2.0.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0

什么是宝石丢失,我该如何解决?

编辑1 :跟随Jesse Sielaff评论/opt/Ruby/gems/bin/jekyll的内容看起来是包装脚本而不是二进制文件:

#!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'jekyll' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/
    version = $1
    ARGV.shift
  end
end

gem 'jekyll', version
load Gem.bin_path('jekyll', 'jekyll', version)

ruby​​和gem是可执行文件(不是链接):

> ls -l /usr/bin/ | egrep 'ruby|gem'
-r-xr-xr-x   1 root   wheel       596 23 Aug  2015 gem*
-r-xr-xr-x   1 root   wheel     42864  5 May  2016 ruby*

0 个答案:

没有答案