[英]How do I install mysql2 gem under Ruby 1.9.3? Works under 2.0.0
I'm having trouble installing the mysql2 gem on my machine. 我在我的机器上安装mysql2 gem时遇到了麻烦。
I have OS X 10.8 with the latest Xcode, and mySql installed via Homebrew. 我有OS X 10.8和最新的Xcode,以及通过Homebrew安装的mySql。 All rubies installed using the latest RVM. 使用最新RVM安装的所有rubies。
I can install mysql2 fine under ruby 2.0.0-p195 我可以在ruby 2.0.0-p195下安装mysql2
[~]$ rvm use 2.0.0 [ruby-1.9.3-p429]
Using /Users/aselder/.rvm/gems/ruby-2.0.0-p195
[~]$ gem in mysql2 [ruby-2.0.0-p195]
Fetching: mysql2-0.3.11.gem (100%)
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed
Under Ruby 1.9.3 and 1.8.7, it can't find the mysql.h file 在Ruby 1.9.3和1.8.7下,它找不到mysql.h文件
[~]$ rvm use 1.9.3 [ruby-1.9.3-p429]
Using /Users/aselder/.rvm/gems/ruby-1.9.3-p429
[~]$ gem in mysql2 [ruby-1.9.3-p429]
Fetching: mysql2-0.3.11.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/aselder/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
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
--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/aselder/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
--with-mysql-config
--without-mysql-config
Gem files will remain installed in /Users/aselder/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/aselder/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
I've also tried all varieties of the command line options to get the gem to find the mysql installation: 我也尝试了各种命令行选项来获取gem以找到mysql安装:
eg gem install mysql2 -- --with-mysql-config=/usr/local/opt/mysql/bin/mysql_config 例如gem install mysql2 - --with-mysql-config = / usr / local / opt / mysql / bin / mysql_config
I found this answer and it solved my issues: Error installing mysql2: Failed to build gem native extension 我找到了这个答案,它解决了我的问题: 安装mysql2时出错:无法构建gem原生扩展
Quoting: 引用:
On Ubuntu/Debian and other distributions using aptitude: 在Ubuntu / Debian和其他使用aptitude的发行版上:
sudo apt-get install libmysql-ruby libmysqlclient-dev
On Red Hat/CentOS and other distributions using yum: 在Red Hat / CentOS和其他使用yum的发行版上:
sudo yum install mysql-devel
On Mac OS X with Homebrew: 在Mac OS X上使用Homebrew:
brew install mysql
I'm on debian and after running the above command, I ran: 我在debian上,在运行上面的命令后,我跑了:
gem install mysql2
and it worked np. 它工作了np。
I solve the problem installing the gem with the mysql server started! 我用mysql服务器启动时解决了安装gem的问题!
brew install mysql
mysql.server start
bundle install
Under ruby-1.9.3-p125. 在ruby-1.9.3-p125下。
Hope this helps 希望这可以帮助
Try to install mysql
using Homebrew and the mysql2
gem using Bundler. 尝试使用Homebrew和使用Bundler的mysql2
gem安装mysql
。
brew update
brew install mysql
Add the following to your Gemfile
将以下内容添加到Gemfile
gem "mysql2"
Run: 跑:
bundle install
I resolved the issue by downgrading mysql from 5.6 to 5.5 through homebrew. 我通过自制软件将mysql从5.6降级到5.5来解决了这个问题。 Can't provide a more detailed explanation, but it fixed it. 无法提供更详细的解释,但它修复了它。
I had a very silly solution to this: I opened Xcode and accepted the license agreement. 我有一个非常愚蠢的解决方案:我打开Xcode并接受了许可协议。 Update downloaded a new version and I couldn't compile anything until the new agreement was manually accepted. 更新下载了新版本,在手动接受新协议之前我无法编译任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.