新手问题 rails s 和 gem mysql2 错误

ckl · 2016年03月11日 · 最后由 suxu 回复于 2016年04月28日 · 2900 次阅读
rails s
  /Library/Ruby/Gems/2.0.0/gems/mysql2-0.4.2/lib/mysql2.rb:31:in `require': dlopen(/Library/Ruby/Gems/2.0.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /Library/Ruby/Gems/2.0.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle
  Reason: unsafe use of relative rpath libmysqlclient.18.dylib in /Library/Ruby/Gems/2.0.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle with restricted binary - /Library/Ruby/Gems/2.0.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle
    from /Library/Ruby/Gems/2.0.0/gems/mysql2-0.4.2/lib/mysql2.rb:31:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `block (2 levels) in require'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
    from /Users/chaikailong/Desktop/gt-management-web/config/application.rb:11:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `block in server'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

之前电脑中 mysql 是通过 dmg 安装的,之后又安装 brew install mysql

试了很多,都没有用!

谢谢大神的帮助

找一个顺手的搜索引擎,去搜搜:Library not loaded: libmysqlclient.18.dylib

#1 楼 @zzxworld 当然都是试过啦! sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib 没有用!谢谢

#1 楼 @zzxworld ln: /usr/lib/libmysqlclient.18.dylib: Operation not permitted

gem uninstall mysql2 gem install mysql2 可能会解决这个问题

#6 楼 @rikiwong @rubyist518 谢谢,是 EI Capital 系统的坑!在 OS X El Capitan 中有一个跟安全相关的模式叫 SIP(System Integrity Protection),它禁止让软件以 root 身份来在 Mac 上运行,在升级到 OS X 10.11 中或许你就会看到部分应用程序被禁用了,这些或许是你通过终端或者第三方软件源安装。对于大多数用户来说,这种安全设置很方便,但是也有些开发者或者高级 Mac 用户不需要这样的设置。 把他关掉就可以啦! 谢谢,能进社区问的,都是搜索了很久没有解决的。所以。。。。

Click the  menu. Select Restart... Hold down command-R to boot into the Recovery System. Click the Utilities menu and select Terminal. Type csrutil disable and press return . Close the Terminal app. Click the  menu and select Restart... .

需要 登录 后方可回复, 如果你还没有账号请 注册新账号