2016-09-21 255 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 **以及那對我工作。 –