宝石不起作用(Mac OS X Snow Leopard,Ruby 1.9.2)
我刚刚编译ruby并安装了rubygems,mysql2和rails,这些工作非常好。 但是,每当我尝试启动rails服务器时,我都会收到以下错误消息:
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `require': dlopen(/usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError) Referenced from: /usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle Reason: image not found - /usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `block (2 levels) in require' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `block in require' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/bundler-1.0.10/lib/bundler.rb:120:in `require' from /Users/filzo/Documents/rails/blog/config/application.rb:7:in `' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:28:in `require' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:28:in `block in ' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:27:in `tap' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:27:in `' from script/rails:6:in `require' from script/rails:6:in `'
我尝试了几种可能的解决方案(例如:http://railsforum.com/viewtopic.php?pid=23125#23125 with libmysqlclient.18.dylib); 但没有为我工作。 我希望你能帮助我。
编辑:它似乎像这样解决了我的问题:
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
无论如何; 这是MySQL或Ruby代码中的错误吗?
最简单也是最好的方法之一是通过命令创建一个软链接 -
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
http://rorguide.blogspot.com/2011/07/getting-error-library-not-loaded.html
这似乎是MySQL二进制发行版中的已知(和未定义的!)错误。
虽然在你的mysql2.bundle文件上运行install_name_tool
可以工作,但如果你删除并重建它们,你又回到了原点。 此外,您必须将此修补程序应用于与其链接的其他任何内容。 更好的解决方案是解决库本身的问题:
$ sudo install_name_tool -id
/usr/local/mysql/lib/libmysqlclient.18.dylib
/usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib
删除并重建mysql2 gem:
$ gem uninstall mysql2
$ gem install mysql2
...会把变化拿到图书馆里去,一切都应该正常工作,而不必修改任何环境变量。
如果你在Mac OS X上使用RVM(一个很好的选择) - 这是最终为我工作的魔法命令。
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Users/*USERNAME*/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
按照当前的设置适当地替换USERNAME。 如果你的mysql版本的gem是不同的,那么也是如此。
链接地址: http://www.djcxy.com/p/57893.html