如何控制宝石安装位置?

时间:2010-10-05 14:03:22

标签: ruby-on-rails rubygems rake 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系统?第一个位置提供了更完整的设置,代表了我的正常环境。由于我的项目依赖于其中的许多项目,并且它们不存在于其他目录中,因此这可以证明是在我的开发环境中从中提取宝石的位置:

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时看不到呢?我能做些什么呢?

2 个答案:

答案 0 :(得分:0)

我看不出问题所在,但您是否尝试过运行“gem list”以查看您的系统识别出已安装的gem?

答案 1 :(得分:0)

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

根据我的了解,当你安装gems时,rails会考虑$ PATH变量,但是当调用rake时加载环境时,它不会。所以rake不知道那些位置。那么,答案是将耙子的注意力引向正确的位置。