环境大概是这样的: max os 10.10. rvm 1.26.3 使用 rvm 安装的 ruby 2.1.5
然后我想安装 mysql2gem 包: gem install mysql2
报以下错误: Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.
/Users/wjf/.rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20141206-1263-1pbvydq.rb extconf.rb checking for ruby/thread.h... yes checking for rb_thread_call_without_gvl() in ruby/thread.h... yes checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... yes checking for rb_hash_dup()... yes checking for rb_intern3()... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lmygcc... no checking for mysql_query() in -lmysqlclient... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
Provided configuration options: --with-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/Users/wjf/.rvm/rubies/ruby-2.1.5/bin/ruby --with-mysql-dir --without-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib --with-mysql-config --without-mysql-config --with-mysql-dir --without-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib --with-mysqlclientlib --without-mysqlclientlib --with-mlib --without-mlib --with-mysqlclientlib --without-mysqlclientlib --with-zlib --without-zlib --with-mysqlclientlib --without-mysqlclientlib --with-socketlib --without-socketlib --with-mysqlclientlib --without-mysqlclientlib --with-nsllib --without-nsllib --with-mysqlclientlib --without-mysqlclientlib --with-mygcclib --without-mygcclib --with-mysqlclientlib --without-mysqlclientlib
extconf failed, exit code 1
Gem files will remain installed in /Users/wjf/.rvm/gems/ruby-2.1.5/gems/mysql2-0.3.17 for inspection. Results logged to /Users/wjf/.rvm/gems/ruby-2.1.5/extensions/x86_64-darwin-14/2.1.0/mysql2-0.3.17/gem_make.out wjfdeMBP:~ wjf$ rvm -v Warning! PATH is not properly set up, '/Users/wjf/.rvm/gems/ruby-2.1.5/bin' is not at first place, usually this is caused by shell initialization files - check them for 'PATH=...' entries, it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles', to fix temporarily in this shell session run: 'rvm use ruby-2.1.5'.
以上错误在 windows/linux 平台上安装 mysql2gem 包的时候也很常见,网上的大部分解决方法都是安装 mysql 数据库及相关的 package,我在 linux 上就是这么解决的,但是现在在 mac 上我不想安装 mysql 数据库,就想搞定这个问题该怎么办? 我在 mysql2 在 github 的主页上看到这样一段: This gem links against MySQL's libmysqlclient C shared library. You may need to install a package such as libmysqlclient-dev, mysql-devel, or other appropriate package for your system.
于是我开始尝试安装那两个 package,可是都安装失败,网上搜了半天也没有合适的方法,特来此求救!