2016-09-21 241 views
34

我在新的macOS Sierra中设置我的开发环境。无法在macOS上安装mysql2 gem Sierra

首先,我安装Rbenv红宝石(2.3.1)自制的MySQL(5.7.15)的最新版本。

$ brew install mysql 
$ mysql.server start 

好吧,MySQL已初始化。在安装的时候mysql2宝石...

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

但没有奏效。通过运行以下

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

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
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

您可以将这些建立标志(本地应用程序):


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 
+0

我不知道这是否回答你的问题:https://stackoverflow.com/questions/30834421/error-when-trying-to-install-app-with-mysql2-gem – spickermann

+0

谢谢,@spickermann。但是它不会帮助我,'brew install openssl'后的结果相同。 –

+2

你也尝试'brew重新安装openssl && brew链接openssl --force' – spickermann

回答

30

当您通过BREW安装OpenSSL的,你应该得到以下信息

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

这对我有效。

有关更多信息,请参阅bundler's documentation

+0

这对我有效。它向我抛出了“零建造”的警告。我尝试在下一行安装捆绑软件,它为我工作。谢啦。 –

+0

是的工作,谢谢你挽救我从我的头撞了几个小时 – dft

96

我刚刚有同样的问题,尝试了上面列出的所有解决方案,然后开始轰炸我的头对着他们的键盘几个小时。

当时我就想试试,并安装/重新安装的Xcode命令行工具:

xcode-select --install 

一旦我做到了安装瓦特/没有问题mysql2宝石。我希望这一招!

+1

也解决了安装nokogiri的问题 –

+1

我更新到MacOS Sierra 10.12.1后遇到同样的问题谢谢! –

+0

完美...... + 1 – abhijit

-2

首先,您应该尝试2个答案here 如果您安装了openssl,但它仍然不起作用。你应该尝试o刷新宝石参考。有同样的问题,它为我工作。

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

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

7

我在这里分享我的修正,因为其他的答案没有工作。

对于我的环境,我需要MySQL 5。6所以我不得不使用:的

brew install mysql56代替brew install mysql

捆绑安装mysql2宝石不停地失败,直到:

brew link mysql56

我也跑算账:

mysql.server start

最后一步可能是不必要的,但是只是以防万一。

+0

与Percona一样,尽管我不得不强制它: 'brew link --force percona-server56' –

1

尝试安装的Xcode,选择--install

1

所以我就遇到了这个类似的问题,对我来说竟然是一个错误的红宝石版本和不兼容的MySQL版本。我在大多数项目中使用ruby 2.3,但继承了2.1项目。更改为rvm使用2.1让我更进一步。

然后我发现这个:https://github.com/brianmario/mysql2/issues/603是说你不得不使用mysql2宝石版本比0.3.17更大的MySQL 5.7版本

更新宝石0.3.17和它发射权利了。希望这可以帮助某人。

1

几乎与@Caio Tarifa,Ruby 2.3.3,mysql 5.6和mysql2一样。试用上面的几个解决方案,最后让它与@ kylekeesling的方法一起工作。

首先,尝试了溶液1通过@spickermann:

brew reinstall openssl && brew link openssl --force 

什么都没有发生,示出同样的错误。

其次,试图在解决方案通过@Alessandro贝拉尔迪:

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

这引起了不同的,但更多的错误,因为它覆盖宝石扩展的配置,因此所有的宝石扩展安装失败。

最后,尝试了@kylekeesling解决方案:

xcode-select --install 

它修复MySQL的宝石问题以及nikogiri。由于我已经安装了Xcode,在我的情况下它重新安装Xcode命令行工具。

+0

也运行命令** xcode-select --install **以及那对我工作。 –