在Mac OS X Lion上安装mysql2 gem

4

前几天,我升级到了Mac OSX Lion。这导致我的rails安装出现问题,因为我必须重新编译mysql。虽然我已经解决了这个问题,但是重新安装mysql2 gem变得困难起来。之前我运行的是leopard,所以我从32位转换到了64位。

  ~/code/rails/london (master)$ gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
  Building native extensions.  This could take a while...
  ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

          /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb --with-mysql-dir=/usr/local/mysql
  checking for rb_thread_blocking_region()... *** 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/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
  /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
  You have to install development tools first.
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:435:in `try_link0'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:440:in `try_link'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:552:in `try_func'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:797:in `block in have_func'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/stewartmatheson/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:796:in `have_func'
    from extconf.rb:9:in `<main>'


  Gem files will remain installed in /Users/stewartmatheson/.rvm/gems/ruby-1.9.2-p0@london/gems/mysql2-0.3.7 for inspection.
  Results logged to /Users/stewartmatheson/.rvm/gems/ruby-1.9.2-p0@london/gems/mysql2-0.3.7/ext/mysql2/gem_make.out

到目前为止,我已经重新编译并安装了MySQL,并将RVM更新到最新版本。我还安装了Xcode,但是没有成功。

有什么建议吗?

4个回答

4

不知道这是否有帮助,但让我试一试。

要使 mysql2 gem 在我的 OSX Lion 上运行,需要运行 Ruby 1.8.7:

安装 mysql - 下载 mysql-5.5.14-osx10.6-x86_64

在 .bash_profile 中创建一个别名来代替 mysql 和 MySQLCOM:

  • alias mysql="/usr/local/mysql/bin/mysql"
  • alias mysqld="sudo /Library/StartupItems/MySQLCOM/MySQLCOM"

安装 gem 'mysql2', '0.3.6'

创建此符号链接:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

我通过编译源代码安装mysql成功了。之后它似乎可以正常工作了。我写了一篇关于这个过程的博客文章,链接是http://rtmatheson.com/2011/09/installing-ruby-1-9-2-on-mac-os-x-10-7-lion/,但是我无法验证你的答案,因为我当时是在尝试构建ruby 1.9.2版本。 - Stewart
我已经在三台 Mac 上完成了它,而且有人点赞了,所以对于使用 Ruby 1.8.7 的人来说可能有效。 - Rafael Oliveira
这对我来说似乎有效[到目前为止,一切顺利]。创建链接的命令是:sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib。 - Snips

4
  1. 从终端输入$ locate mysql_config命令,以便找到路径。
  2. 然后输入$ sudo gem install mysql2 -- –with-mysql-config=/path/to/mysql_config命令安装mysql2。

3

我按照以下步骤在系统Ruby(Lion上的1.8.7)中安装了它:

  1. Install 64-bit MySQL 5.5.19 64-bit from the .dmg
  2. Add /usr/local/mysql/lib to your DYLD_LIBRARY_PATH (I prefer this to the symbolic link solution but they should be equivalent). I did this in my .bash_profile via:

    export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
    
  3. Execute:

    env ARCHFLAGS="-arch x86_64" sudo gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config
    

1

我通过重新安装Ruby解决了这个问题——因为在Lion中更新了编译器,所以这似乎是必需的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接