如何控制 gem 安装位置?

发布于 2024-09-26 07:58:38 字数 4698 浏览 1 评论 0原文

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

我看不出问题是什么是。我快要疯了。 “其他”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 时看不到它?我能做什么呢?

Lots of confusion and difficulty related to gem installation. My gem environment:

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/

The problem is one where I will add (eg) to environment.rb :

  config.gem 'authlogic'

All good, now when I run

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.

running it with sudo is fine :

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

but running rake tasks throws an error :

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.

I can't see what the problem is. And I'm going out of my mind. The directory at the 'other' gems location :

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

This, I assume, is the default OSX rails system? The first location gives the much fuller set that represents my normal environment. Since my projects depend on many of these, and they aren't present in the other directory, this is verifiably the location that gems are being pulled from in my development environment:

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

So, if the system uses this /opt/local/lib/ruby/gems/1.8/gems directory, why can't it see it when I call rake? And what can I do about it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长伴 2024-10-03 07:58:38

我不明白问题是什么,但是您是否尝试运行“gem list”来查看系统识别为已安装的gem?

I don't see what the problem is, but have you tried running "gem list " to see what gems your system recognizes as having installed?

鸠魁 2024-10-03 07:58:38

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

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

My solution was to change the #! line of rake.rb to point to the location of the ruby installation that has the gems.

From what I learned, when you're installing gems, rails takes account of the $PATH variable, but when loading the environment when rake is called, it doesn't. So rake doesn't know about those locations. The answer, then, was to direct rake's attention to the right location.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文