在mac上安装mysql2 gem rails

时间:2012-10-10 03:19:49

标签: ruby rubygems mysql2

我正在尝试安装mysql2的gem,但看起来它没有找到安装mysql的地方。我在我的mac上使用XAMPP堆栈安装了mysql。我读了其他帖子,但没有结果。

sudo  gem install mysql2 -- --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config 
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

        /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing.  please check your installation of mysql and try again.
-----
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --with-mysql-config


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11 for inspe

1 个答案:

答案 0 :(得分:1)

在构建本机扩展时,gem正在寻找mysql头。这些可能在/Application/XAMPP/...中,您可以通过以下参数指向gem -

--with-mysql-dir=/path/to/mysql \
--with-mysql-include=/path/to/mysql/headers \
--with-mysql-lib=/path/to/lib \
--with-mysql-config=/path/to/configs

或者,如果没有必要使用XAMPP的mysql,你可以通过homebrew获取mysql然后 -

brew install mysql 
gem install mysql2

我更喜欢第二种方式。它更清晰,更少混乱,因为我不知道XAMPP对它们捆绑的mysql做了什么改变;)

稍后如果您需要在Linux vps上设置此类宝石,并遇到类似问题,请记住安装-dev软件包。例如。 libmysqlclient-dev用于mysql。