【问题标题】:How can I get control of gem installation locations?如何控制 gem 安装位置?
【发布时间】:2010-10-05 14:03:21
【问题描述】:

与 gem 安装相关的许多困惑和困难。我的 gem 环境:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
  - INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /opt/local/bin/ruby
  - EXECUTABLE DIRECTORY: /opt/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-darwin-10
  - GEM PATHS:
     - /opt/local/lib/ruby/gems/1.8
     - /Users/apple/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["http://gems.rubyforge.org/"]
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/

问题是我将添加(例如)到 environment.rb 的问题:

  config.gem 'authlogic'

一切都好,现在当我运行时

gem install authlogic
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /opt/local/lib/ruby/gems/1.8 directory.

用 sudo 运行它很好:

Dans-iMac-335:authlogic apple$ sudo rake gems:install
Password:
(in /Users/apple/Documents/projects/authlogic)
gem install authlogic
Successfully installed authlogic-2.1.6
1 gem installed
Installing ri documentation for authlogic-2.1.6...
Installing RDoc documentation for authlogic-2.1.6...

但运行 rake 任务会引发错误:

Dans-iMac-335:authlogic apple$ rake db:migrate
(in /Users/apple/Documents/projects/authlogic)
Missing these required gems:
  authlogic  

You're running:
  ruby 1.8.7.174 at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  rubygems 1.3.5 at /Users/apple/.gem/ruby/1.8, /Library/Ruby/Gems/1.8, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

Run `rake gems:install` to install the missing gems.

我看不出问题出在哪里。我快疯了。 “其他”宝石位置的目录:

Dans-iMac-335:authlogic apple$ ls /Users/apple/.gem/ruby/1.8/gems
actionmailer-2.2.2  activeresource-2.2.2    aws-s3-0.6.2        mysql-2.8.1     rails-2.2.2     xml-simple-1.0.12
actionpack-2.2.2    activeresource-2.3.3    builder-2.1.2       packet-0.1.15       rake-0.8.7
actionwebservice-1.2.3  activesupport-2.2.2 chronic-0.2.3       pg-0.8.0        rest-client-1.3.1
activerecord-2.2.2  activesupport-2.3.3 mime-types-1.16     rack-1.0.0      sqlite3-ruby-1.0.1
activerecord-2.3.5  activesupport-2.3.5 mongrel-1.1.5       rack-1.0.1      taps-0.2.26

我认为这是默认的 OSX rails 系统吗?第一个位置提供了代表我正常环境的更完整的集合。由于我的项目依赖于其中的许多,并且它们不存在于其他目录中,因此可以验证这是从我的开发环境中提取 gem 的位置:

Dans-iMac-335:authlogic apple$ ls /opt/local/lib/ruby/gems/1.8/gems
RedCloth-4.2.3          crack-0.1.8         mime-types-1.16         rack-1.1.0          sinatra-0.9.2
actionmailer-2.3.5      daemons-1.0.10          minitest-1.4.2          radiant-0.8.1           sinatra-1.0
actionmailer-2.3.8      faker-0.3.1         mogli-0.0.14            rails-2.2.2         spree-0.10.2
actionpack-2.3.5        fastthread-1.0.7        mongrel-1.1.5           rails-2.3.5         sqlite3-ruby-1.0.1
actionpack-2.3.8        gem_plugin-0.2.3        mutter-0.5.3            rails-2.3.8         sqlite3-ruby-1.2.5
activemerchant-1.5.1        google-geocode-1.2.1        mysql-2.8.1         rc-rest-3.0.0           state_machine-0.8.0
activerecord-2.3.8      hashie-0.4.0            net-scp-1.0.2           rest-client-1.0.3       stringex-1.0.3
activerecord-tableless-0.1.0    heroku-1.10.8           net-sftp-2.0.2          rest-client-1.6.1       taps-0.2.19
activeresource-2.3.5        highline-1.5.1          net-ssh-2.0.15          rmagick-2.13.1          taps-0.3.13
activeresource-2.3.8        hoe-2.3.3           net-ssh-gateway-1.0.1       ruby-hmac-0.4.0         thor-0.9.9
activesupport-2.3.8     hpricot-0.8.1           nokogiri-1.3.3          ruby-openid-2.1.7       treetop-1.4.8
authlogic-2.1.6         httparty-0.6.1          paperclip-2.3.1.1       rubyforge-2.0.2         whenever-0.3.7
authlogic-oid-1.0.4     json-1.1.9          passenger-2.2.5         rubyforge-2.0.4         will_paginate-2.3.11
aws-s3-0.6.2            json_pure-1.1.9         pg-0.8.0            rubygems-update-1.3.5       xml-simple-1.0.12
builder-2.1.2           json_pure-1.2.4         pg-0.9.0            rubygems-update-1.3.7
capistrano-2.5.9        launchy-0.3.3           polyglot-0.3.1          searchlogic-2.3.5
cgi_multipart_eof_fix-2.5.0 less-1.2.20         postgres-0.7.9.2008.01.28   sequel-3.0.0
configuration-1.1.0     libxml-ruby-1.1.3       rack-1.0.1          sequel-3.15.0

那么,如果系统使用这个/opt/local/lib/ruby/gems/1.8/gems目录,为什么我调用rake时看不到呢?我该怎么办?

【问题讨论】:

    标签: ruby-on-rails rubygems rake gem


    【解决方案1】:

    我不知道问题出在哪里,但是您是否尝试过运行“gem list”来查看您的系统识别为安装了哪些 gem?

    【讨论】:

    • 我做到了,“缺失”的宝石就在其中。但是请参阅下面的答案:问题似乎是当 rake 运行并加载环境时,它不使用 rails 在安装 gems 时使用的 $PATH 变量。
    【解决方案2】:

    我的解决方案是更改 #! rake.rb 行指向具有 gem 的 ruby​​ 安装位置。

    据我所知,当您安装 gems 时,rails 会考虑 $PATH 变量,但是在调用 rake 时加载环境时,它不会。所以 rake 不知道这些位置。因此,答案是将 rake 的注意力引导到正确的位置。

    【讨论】:

      猜你喜欢
      • 2013-10-05
      • 2022-11-23
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多