库未加载错误 - 错误的 ruby [英] Library not loaded error -- wrong ruby
问题描述
我将 RVM 与 Ruby 1.9.3 p448 一起使用,但是当我尝试运行 Rails 服务器时,出现此错误(以及其他一些内容)
I'm using RVM with Ruby 1.9.3 p448, but when I try to run my rails server, I get this error (plus some other stuff)
9): Library not loaded: /Users/sashafklein/.rvm/rubies/ruby-1.9.3-p327/lib/libruby.1.9.1.dylib (LoadError)
Referenced from: /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/posix-spawn-0.3.6/lib/posix_spawn_ext.bundle
Reason: image not found - /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/posix-spawn-0.3.6/lib/posix_spawn_ext.bundle
奇怪的是,它引用了 ruby-1.9.3-p327,它甚至不是我的 RVM 安装之一.我应该删除那个没有找到 libruby 的 Ruby 文件夹吗?或者还有什么问题?
The weird thing is, it's referencing ruby-1.9.3-p327, which isn't even one of my RVM installs. Should I delete that Ruby folder it's not finding libruby in? Or what else might be wrong?
编辑 -- 完整错误
/Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require': dlopen(/Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/posix-spawn-0.3.6/lib/posix_spawn_ext.bundle, 9): Library not loaded: /Users/sashafklein/.rvm/rubies/ruby-1.9.3-p327/lib/libruby.1.9.1.dylib (LoadError)
Referenced from: /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/posix-spawn-0.3.6/lib/posix_spawn_ext.bundle
Reason: image not found - /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/posix-spawn-0.3.6/lib/posix_spawn_ext.bundle
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/posix-spawn-0.3.6/lib/posix/spawn.rb:2:in `<top (required)>'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/posix-spawn-0.3.6/lib/posix-spawn.rb:1:in `<top (required)>'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/albino-1.3.3/lib/albino.rb:1:in `<top (required)>'
from /Users/sashafklein/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /Users/sashafklein/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /Users/sashafklein/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /Users/sashafklein/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /Users/sashafklein/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /Users/sashafklein/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /Users/sashafklein/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /Users/sashafklein/rails/<appname>/config/application.rb:12:in `<top (required)>'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from /Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
albino gem 好像在这个最底层,但是我觉得是app需要的,所以不能随便拿出来.我尝试了 gem uninstall albino (没有输出)然后捆绑安装,但这并没有解决任何问题.与 bundle update 类似,下面还有 mpapis 和 sahil 的帮助.
The albino gem seems to be at the bottom of this, but I think it's necessary for the app, so I can't just take it out. I tried gem uninstall albino (which gave no output) and then bundle install, but that didn't fix anything. Likewise with bundle update, and likewise with mpapis's and sahil's help below.
推荐答案
当 gem 链接错误时可能会发生这种情况,试试这个:
this kind of thing could happen when gems are linked wrong, try this:
rvm get head
rvm reinstall 1.9.3-p448
rvm use 1.9.3-p448
这将重新安装 ruby 并使所有 gems 保持原始状态,这应该可以防止此类问题的发生 - 除非 gem 作者做了一些超出标准 ruby 检测的额外技巧.
This will reinstall the ruby and make all gems pristine, which should prevent such problems from happening - unless gem authors did some extra tricks which go out of standard ruby detection.
使用 bundler
的标志 --deployment
或 --path
并不总是安全的,错误信息说:
Using bundler
s flag --deployment
or --path
is not always safe, the error message says:
/Users/sashafklein/rails/<appname>/vendor/bundle/ruby/1.9.1/gems/posix-spawn-0.3.6/lib/posix_spawn_ext.bundle
这意味着 gem 是用其他 ruby 编译的,现在找不到了.
Which means the gem was compiled with the other ruby and now can not find it.
修复它的最简单方法是停止使用 --deployment
标志,因为它被持久化,摆脱它(以及所有其他潜在危险设置)的最简单方法是:
The simplest way to fix it is to stop using --deployment
flag, as it is persisted the easiest way to get rid of it (and all other potentially dangerous settings) is:
rm -rf .bundle/ vendor/bundle
bundle install
解释
Bundler 在运行时过滤 gems 做得很好,不幸的是它使用 --deployment
标志强制执行另一层过滤,这会强制将 gems 安装到多个 ruby 通用的路径 - 在这种情况下: ruby/1.9.1
,这是不安全的,因为 rubies 可以用不同的设置编译,这会破坏不同 ruby 中使用的 c-extension gem.
Interpretation
Bundler does great job filtering gems in runtime, unfortunately it enforces another layer of filtering with the --deployment
flag, which forces installation of gems to path that is common for multiple rubies - in this case: ruby/1.9.1
, this is unsafe as rubies can be compiled with different settings which can break c-extension gems used in different ruby.
这篇关于库未加载错误 - 错误的 ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!