OSX 10.11上的Rails El Capitan:未加载库:libmysqlclient.18.dylib

时间:2015-10-08 08:58:27

标签: mysql ruby-on-rails macos

由于我将OSX升级到10.11,我不再使用MySQL和我的Rails应用程序了:

$ rails s
/Users/josh/.rvm/gems/ruby-2.2.3@a4aa2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require': dlopen(/Users/josh/.rvm/gems/ruby-2.2.3@a4aa2/gems/mysql2-0.3.20/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /Users/josh/.rvm/gems/ruby-2.2.3@a4aa2/gems/mysql2-0.3.20/lib/mysql2/mysql2.bundle
  Reason: image not found - /Users/josh/.rvm/gems/ruby-2.2.3@a4aa2/gems/mysql2-0.3.20/lib/mysql2/mysql2.bundle
    from /Users/josh/.rvm/gems/ruby-2.2.3@a4aa2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/josh/.rvm/gems/ruby-2.2.3@a4aa2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/josh/.rvm/gems/ruby-2.2.3@a4aa2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'

我发现了其他类似问题的帖子,但我在这方面太初学了,版本因解决而改变等等。

2 个答案:

答案 0 :(得分:52)

之前的答案(前El Capitan),是从mysql的lib目录创建一个符号链接,用于库文件到/ usr / lib,如下所示:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

然而,这现在产生了不允许的操作'由于OS X的完整性控制。这可以通过禁用它来解决。然而,一个更简单的解决方案(我可以验证的解决方案)是将其符号链接到/ usr / local / lib中:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib

好的'苹果。

答案 1 :(得分:1)

我有同样的问题,只是打开终端命中:

sudo nano ~/.bash_profile

粘贴以下行:

MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

就是这样。