[英]ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. on Mac 10.12
I tried every solution similar to the question:
我尝试了类似问题的每个解决方案:
Recently , I moved from ubuntu to Mac and I'm trying to install mysql gem on Sierra and after I had installed Ruby , Rails , Mysql, 最近,我从ubuntu转移到Mac,我试图在Sierra上安装mysql gem,之后我安装了Ruby,Rails,Mysql,
also I type brew install mysql
and it worked for download mysql but not the gem , so my question is not similar. 我也输入
brew install mysql
,它可以下载mysql而不是gem,所以我的问题并不相似。
I typed this mysql --version
我输入了这个
mysql --version
and I got mysql Ver 14.14 Distrib 5.7.16, for osx10.12 (x86_64) using EditLine wrapper
我
mysql Ver 14.14 Distrib 5.7.16, for osx10.12 (x86_64) using EditLine wrapper
获得了mysql Ver 14.14 Distrib 5.7.16, for osx10.12 (x86_64) using EditLine wrapper
I tried to install mysql2 gem for rails to build a new app 我试图安装mysql2 gem for rails来构建一个新的应用程序
I typed this sudo gem install mysql2
and got this error: 我输入了这个
sudo gem install mysql2
并得到了这个错误:
Password:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
/Users/mohammed.elias/.rbenv/versions/2.4.0/bin/ruby -r ./siteconf20170102-2045-18gcs95.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
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
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't 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.16/lib
-----
creating Makefile
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/mysql2-0.4.5/mkmf.log
current directory: /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/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/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysq l2-0.4.5 for inspection.
Results logged to /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/mysql2-0.4.5/gem_make.out
我的问题很好的答案,感谢@Holger只是在githup ld上引用这个问题:在Mac OS Sierra升级后找不到-lssl`的库
Had this exact same problem when installing MySQL2 gem on a fresh Macbook Pro Sierra. 在新的Macbook Pro Sierra上安装MySQL2 gem时遇到了同样的问题。
You need to alter your environment variables to include the following (just replace the 0.0.00 with the desired version of MySQL2 gem: 您需要更改环境变量以包含以下内容(只需将0.0.00替换为所需的MySQL2 gem版本:
gem install mysql2 -v '0.0.00' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
Also, your $PATH
should be set up with mysql with bash profile, a list of settings that will be run every time bash starts. 此外,您的
$PATH
应该使用带有bash配置文件的mysql进行设置,这是每次bash启动时都会运行的设置列表。 Your bash profile can be found in your home directory under the filename .bash_profile
. 您的bash配置文件可以在您的主目录中找到,文件
.bash_profile
。 If it is not created, you can create the text file using the command nano .bash_profile
(you should be in your home directory (~)). 如果未创建,则可以使用命令
nano .bash_profile
创建文本文件(您应该在主目录(〜)中)。 Add this to your bash profile: 将其添加到您的bash配置文件中:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
This line will add the above directories to your path, including the mysql path. 该行将上述目录添加到您的路径中,包括mysql路径。 Make sure you restart your terminal, as .bash_profile only runs when the terminal is initially loaded.
确保重新启动终端,因为.bash_profile仅在最初加载终端时运行。
由于某种原因运行xcode-select --install
,为我解决了这个问题。
For anybody still experiencing the issue: 对于仍然遇到问题的人:
Run xcode-select --install
will set up your command line tools 运行
xcode-select --install
将设置命令行工具
then 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"
and then finally: bundle install
to install the mysql2
gem and other gems worked for me. 然后最后:
bundle install
以安装mysql2
gem和其他宝石为我工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.