简体   繁体   English

尝试在OS X上安装mysql gem时出错

[英]Error when trying to install mysql gem on os x

I am trying to add mysql to my Gemfile and install it when running bundle install. 我正在尝试将mysql添加到我的Gemfile中,并在运行捆绑安装时安装它。 I get the following error. 我收到以下错误。

Installing mysql (2.8.1) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h

I have also tried running sudo before gem mysql. 我也尝试在mysql之前运行sudo。 Any thoughts on how to fix issue would be great. 关于如何解决问题的任何想法都会很棒。

thanks, Matthew 谢谢,马修

As Tadman mentioned you need to install the developer tools for this to work. 正如Tadman提到的那样,您需要安装开发人员工具才能正常工作。 But what the error message is telling us it that you are missing some mysql header files. 但是错误消息告诉我们它缺少一些mysql头文件。 I don't know if you are using a 64bit (mac i assume?) system om 32 bit. 我不知道您是否在使用32位的64位(我假设是Mac?)系统。 In the 64bit case you can do this: 在64位的情况下,您可以执行以下操作:

Download mysql. 下载mysql。 http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.51-osx10.6-x86_64.dmg/from/http://mirror.leaseweb.com/mysql/ http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.51-osx10.6-x86_64.dmg/from/http://mirror.leaseweb.com/mysql/

Then install the gem with the correct bindings. 然后使用正确的绑定安装gem。 I never tried it with RVM so you should! 我从来没有尝试过RVM,所以您应该!

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

Do you have the OS X developer tools installed? 您是否安装了OS X开发人员工具? If you're missing XCode, you may not have key components such as the header files for Ruby and MySQL. 如果缺少XCode,则可能没有关键组件,例如Ruby和MySQL的头文件。

If you're using the default system Ruby, it might be worth the trouble to use either MacPorts or RVM to manage your installation. 如果您使用默认系统Ruby,则使用MacPortsRVM来管理安装可能会很麻烦。 Personally I like MacPorts better since it also helps with installing various system libraries that might be required. 我个人更喜欢MacPorts,因为它还有助于安装可能需要的各种系统库。

Here's an example on how to install using MacPorts. 这是有关如何使用MacPorts安装的示例 It was formerly called Darwin Ports, but the principle is the same. 它以前称为Darwin Ports,但原理是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM