使用Ruby 1.9.2和Rails 3.1在OS X 10.7上运行Rails gem mysql2的问题

时间:2011-09-27 02:40:39

标签: ruby-on-rails ruby gem osx-lion mysql2

操作系统版本: Mac OS X 10.7.1 Lion
Ruby版本: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]
Ruby位置: /usr/local/rvm/bin/ruby
Rails版本: Rails 3.1.0
Rails位置: /usr/local/rvm/gems/ruby-1.9.2-p290/bin/rails

现在,我安装了mysql2 gem,当我运行gem list时,它会在列表中显示为:mysql2 (0.3.7)

到目前为止这么好,对吗?好的,所以这里变得棘手。无论我做什么,我都无法启动服务器。在终端我cd到我的rails应用程序目录并运行rails s。但是,而不是开始我得到这个:

/usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2.rb:9:in `require': dlopen(/usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle
  Reason: image not found - /usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2.rb:9:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `each'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `block in require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `each'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler.rb:120:in `require'
    from /Users/doug/Sites/simple_cms/config/application.rb:7:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:52:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:52:in `block in <top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:49:in `tap'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:49:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

显然,这不应该发生什么。问题是我无法弄清楚为什么不。我遇到的解决方案都没有奏效。

这实际上是我第一次尝试在我的计算机上运行Ruby / RoR。我正在关注Lynda.com的教程,不出所料,这不会发生在制作视频的人身上。

我试过搜索,正如我所说,似乎没有任何帮助。想法?

1 个答案:

答案 0 :(得分:2)

install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p290@[gemset name]/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle

[宝石名称] =您正在使用的宝石集的名称 - 如果您没有设置它,那么您应该将其设置为获取rvm的主要要点之一

希望有所帮助