使用Mac OSX 10.6为Ruby on Rails安装mysql2 gem
我在安装mysql2 gem时遇到问题。
当我做gem install mysql2
:
Marks-MacBook-Pro:~ Mark$ gem install mysql2 Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. /Users/useruser/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb checking for rb_thread_blocking_region()... 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 --without-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/useruser/.rvm/rubies/ruby-1.9.2-p136/bin/ruby --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 Gem files will remain installed in /Users/useruser/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6 for inspection. Results logged to /Users/useruser/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
当我使用rails server
这就出现了:
Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
看来它找不到MySQL库。 你安装了MySQL吗?
尝试通过自制程序安装它:
brew install mysql
或者通过macports或fink或任何你喜欢的方式安装它,然后再试一次:
gem install mysql2
这个命令对我有用:
gem install mysql2 -- --srcdir=/usr/local/mysql/include
我在Mac OS X上不需要MySQL,因为我在Vagrant盒子上安装了MySQL。 因此,我刚刚安装了mysql-connector-c。
brew install mysql-connector-c gem install mysql2
以下命令成功地为我工作。
xxx =您要安装的mysql2的版本。
gem install mysql2 -v 'xxx' -- --srcdir=/usr/local/mysql/include
以下对我有用
brew install mysql brew install mysql-connector-c gem install mysql2
您必须指定一些额外的环境变量才能在Mac OSX 10.6的64位架构上安装此gem:
env ARCHFLAGS="-arch x86_64" gem install mysql2
如果您使用的是rvm,可以在〜/ .rvmrc文件中将其添加为默认选项:
rvm_archflags="-arch x86_64"
如果你使用自制软件来安装mysql, brew install mysql
,这对我有用:
gem install mysql2 -v 'xxx' -- --with-mysql-config=/usr/local/Cellar/mysql/yyy/bin/mysql_config
xxx =您要安装的mysql2 gem的版本
yyy =你已经安装了ls /usr/local/Cellar/mysql
来找到它。
获取mysql的版本
brew info mysql mysql: stable 5.7.19 (bottled) ... /usr/local/Cellar/mysql/5.7.19 (322 files, 233MB) * ...
那么如果你想用bundle安装:
bundle config build.mysql --with-mysql-config=/usr/local/Cellar/mysql/yyy/bin/mysql_config
我有完全相同的问题和错误尝试安装mysql2。 我认为我的mamp安装的MySQL可以正常工作并花了几个小时来玩这些工作的路径 – 没有成功。
终于从ALoR发现了这篇文章并通过自制软件安装了一个新版本 – 但是 – 请务必按照自制程序中的所有说明进行操作! 我错过了几个步骤,浪费了另一个小时来追踪这个问题 – 这是那些说明: https : //stackoverflow.com/a/11061487/1241271
MySQL成功安装后,我运行: sudo gem install mysql2
,它就像一个魅力。
希望这可以帮助某人浪费几个小时,因为他们忽略了阅读文档(newb错误)。