2010-10-05 81 views
1

與寶石安裝有關的許多困惑和困難。我的寶石環境:如何控制寶石安裝位置?

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... 

b ut運行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導軌系統?第一個位置提供了更完整的設置,代表了我的正常環境。由於我的項目取決於許多的這些,他們是不存在於其他目錄,這是可覈查的是寶石正從我的開發環境拉到位置:

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時無法看到它?我能做些什麼呢?

回答

0

我沒有看到問題所在,但是您是否嘗試過運行「gem list」以查看您的系統認爲安裝了哪些寶石?

+0

我做了,並且「失蹤」的寶石在裏面。但請參閱下面的答案:問題似乎是,當rake運行並加載環境時,它不會使用rails在安裝gem時使用的$ PATH變量。 – 2010-10-07 13:25:26

0

我的解決方案是改變#! rake.rb行指向具有寶石的紅寶石安裝位置。

從我所瞭解的情況來看,當您安裝gem時,rails會考慮$ PATH變量,但是當調用rake時加載環境時,它不會。所以耙子不知道那些位置。那麼答案就是把耙子的注意力引向正確的位置。