简体   繁体   English

无法在 macOS Sierra 上安装 mysql2 gem

[英]Can't install mysql2 gem on macOS Sierra

I'm setting up my development environment in the new macOS Sierra .我正在新的macOS Sierra  中设置我的开发环境。

First of all, I installed Rbenv , Ruby (2.3.1) , Homebrew and so the latest version of MySQL (5.7.15) .首先,我安装了RbenvRuby (2.3.1)Homebrew等等最新版本的MySQL (5.7.15)

$ brew install mysql
$ mysql.server start

Ok, MySQL was initialized.好的,MySQL 已初始化。 Time to install the mysql2 gem...是时候安装mysql2 gem...

$ gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.7.15/bin/mysql_config

But it didn't work.但它没有用。 😞 😞


Building native extensions with: '--with-mysql-config=/usr/local/Cellar/mysql/5.7.15/bin/mysql_config'
This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /Users/macuser/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
/Users/macuser/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20160921-16853-x1boio.rb extconf.rb --with-mysql-config=/usr/local/Cellar/mysql/5.7.15/bin/mysql_config
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/Cellar/mysql/5.7.15/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Dont know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql/5.7.15/lib
-----
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/macuser/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.4.4/mkmf.log

current directory: /Users/macuser/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/macuser/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/macuser/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4 for inspection.
Results logged to /Users/macuser/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.4.4/gem_make.out

I just had the same problem, tried all of the solutions listed above, then commenced to bang my head against they keyboard for a couple of hours.我刚刚遇到了同样的问题,尝试了上面列出的所有解决方案,然后开始用头撞他们的键盘几个小时。

I then thought to try and install/reinstall the Xcode Command Line Tools:然后我想尝试安装/重新安装 Xcode 命令行工具:

xcode-select --install

Once I did that the mysql2 gem installed w/ no problems.一旦我这样做了 mysql2 gem 安装没有问题。 I hope that does the trick!我希望这能解决问题!

When you install openssl via brew, you should get the following message:当您通过 brew 安装 openssl 时,您应该收到以下消息:

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries Apple 已弃用 OpenSSL,转而使用自己的 TLS 和加密库

Generally there are no consequences of this for you.一般来说,这对您没有任何后果。 If you build your own software and it requires this formula, you'll need to add to your build variables:如果您构建自己的软件并且需要此公式,则需要添加到构建变量中:

LDFLAGS: -L/usr/local/opt/openssl/lib LDFLAGS:-L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include CPPFLAGS:-I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig PKG_CONFIG_PATH:/usr/local/opt/openssl/lib/pkgconfig

You can set these build flags (for the local application) by running the following:您可以通过运行以下命令来设置这些构建标志(对于本地应用程序):

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

This worked for me.这对我有用。

See bundler's documentation for more information.有关更多信息,请参阅捆绑程序的文档

Lots of great answers, I was able to combine them into this:很多很棒的答案,我能够将它们组合成这样:

gem install mysql2 --source 'https://rubygems.org/' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

because I was not comfortable with bundle config因为我对bundle config不满意

I am here to share my fix, since the other answers didn't work.我在这里分享我的修复,因为其他答案不起作用。

For my environment, I need MySQL 5.6 so I had to use:对于我的环境,我需要 MySQL 5.6,所以我不得不使用:

brew install mysql56 instead of brew install mysql brew install mysql56而不是brew install mysql

Bundle installing the mysql2 gem kept failing, until:捆绑安装 mysql2 gem 一直失败,直到:

brew link mysql56

I also ran afterwards:后来我也跑了:

mysql.server start

The last step might be unnecessary, but just in case.最后一步可能是不必要的,但以防万一。

With Mac OS 10.15 Catalina when I tried Alessandro's fix the gem and extensions could be installed correctly but bundle install failed.在 Mac OS 10.15 Catalina 中,当我尝试 Alessandro 的修复程序时,可以正确bundle install gem 和扩展,但bundle install失败。 What worked was just:有效的是:

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

without the cppflags part.没有cppflags部分。

Here's what worked for me.这对我有用。

Originally I ran:最初我跑了:

$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

then那么

$ bundle install

I received an error in /Users/.../.bundle/ruby/2.5.0/extensions/x86_64-darwin-18/2.5.0/mysql2-0.5.3/mkmf.log :我在 /Users/.../.bundle/ruby/2.5.0/extensions/x86_64-darwin-18/2.5.0/mysql2-0.5.3/mkmf.log 中收到错误:

clang: error: unsupported option '--with-cppflags=-I/usr/local/opt/openssl/include' clang:错误:不支持的选项'--with-cppflags=-I/usr/local/opt/openssl/include'

So I removed "--with-cppflags=-I/usr/local/opt/openssl/include"所以我删除了“--with-cppflags=-I/usr/local/opt/openssl/include”

Then ran:然后跑:

$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

followed by:其次是:

$ bundle install

Which worked.哪个有效。

Almost the same scenario as @Caio Tarifa, Ruby 2.3.3, mysql 5.6 and mysql2.与@Caio Tarifa、Ruby 2.3.3、mysql 5.6 和 mysql2 几乎相同的场景。 Tried on couple of solutions above and finally make it work with @kylekeesling's approach.尝试了上面的几个解决方案,最后使它与@kylekeesling 的方法一起工作。

First, tried on solution 1 by @spickermann:首先,通过@spickermann 尝试解决方案 1:

brew reinstall openssl && brew link openssl --force

Nothing happened, same error shown.什么也没发生,显示相同的错误。

Second, tried on solution by @Alessandro Berardi:其次,通过@Alessandro Berardi 尝试解决方案:

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

This got different but more errors since it overwrite gem extension's config so all gem extension installation failed.这有不同但更多的错误,因为它覆盖了 gem 扩展的配置,所以所有 gem 扩展安装都失败了。

Finally, tried on @kylekeesling solution:最后,尝试了@kylekeesling 解决方案:

xcode-select --install

It fix mysql gem issue as well as nikogiri.它修复了 mysql gem 问题以及 nikogiri。 Since I already intall Xcode, in my case it's reinstall the Xcode Command Line Tools.由于我已经安装了 Xcode,在我的情况下,它是重新安装 Xcode 命令行工具。

尝试安装 xcode-select --install

So I ran into this similar issue and for me it turned out to be a wrong ruby version and incompatible MySQL version.所以我遇到了这个类似的问题,对我来说结果是错误的 ruby​​ 版本和不兼容的 MySQL 版本。 I use ruby 2.3 on most of my projects but inherited a 2.1 project.我在大多数项目中使用 ruby​​ 2.3,但继承了 2.1 项目。 Changing to rvm to use 2.1 got me a little further.更改为 rvm 以使用 2.1 让我更进一步。

Then I found this: https://github.com/brianmario/mysql2/issues/603 that said you had to use mysql2 gem version greater than 0.3.17 with MySQL version 5.7然后我发现这个: https : //github.com/brianmario/mysql2/issues/603说你必须使用 mysql2 gem 版本大于 0.3.17 和 MySQL 版本 5.7

Updated gem to 0.3.17 and it fired right up.将 gem 更新到 0.3.17 并立即启动。 Hope this helps someone.希望这可以帮助某人。

I have a problem like this. 我有这样的问题。 Hope this could be useful . 希望这可能有用。

brew install mysql@5.6

brew link mysql@5.6 --force

bundle install

this answer help me ! 这个答案对我有帮助!

If none of the above works .. like in my case, doing this solved the issue brew install openssl如果以上都不起作用..就像在我的情况下,这样做解决了问题brew install openssl

FYI: i am using MacOS Catalina仅供参考:我正在使用 MacOS Catalina

So I tried everything here to no avail.所以我在这里尝试了一切都无济于事。 Seems like a problem with ruby 2.6.0, I downgraded to 2.3.4p301 and everything worked fine (with bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include" )似乎是 ruby​​ 2.6.0 的问题,我降级到 2.3.4p301 并且一切正常(使用bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include" )

First, you should try 2 answer in here If you installed openssl but it still don't work.首先,您应该在这里尝试 2 个答案如果您安装了 openssl 但它仍然不起作用。 You should try to o refresh gems reference.您应该尝试刷新 gems 参考。 A got the same issue and it worked for me. A 遇到了同样的问题,它对我有用。

gem source -r https://rubygems.org/

gem source -a https://rubygems.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM