[英]How do I install mysql2 gem under Ruby 1.9.3? Works under 2.0.0
我在我的機器上安裝mysql2 gem時遇到了麻煩。
我有OS X 10.8和最新的Xcode,以及通過Homebrew安裝的mySql。 使用最新RVM安裝的所有rubies。
我可以在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
在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
我也嘗試了各種命令行選項來獲取gem以找到mysql安裝:
例如gem install mysql2 - --with-mysql-config = / usr / local / opt / mysql / bin / mysql_config
我找到了這個答案,它解決了我的問題: 安裝mysql2時出錯:無法構建gem原生擴展
引用:
在Ubuntu / Debian和其他使用aptitude的發行版上:
sudo apt-get install libmysql-ruby libmysqlclient-dev
在Red Hat / CentOS和其他使用yum的發行版上:
sudo yum install mysql-devel
在Mac OS X上使用Homebrew:
brew install mysql
我在debian上,在運行上面的命令后,我跑了:
gem install mysql2
它工作了np。
我用mysql服務器啟動時解決了安裝gem的問題!
brew install mysql
mysql.server start
bundle install
在ruby-1.9.3-p125下。
希望這可以幫助
嘗試使用Homebrew和使用Bundler的mysql2
gem安裝mysql
。
brew update
brew install mysql
將以下內容添加到Gemfile
gem "mysql2"
跑:
bundle install
我通過自制軟件將mysql從5.6降級到5.5來解決了這個問題。 無法提供更詳細的解釋,但它修復了它。
我有一個非常愚蠢的解決方案:我打開Xcode並接受了許可協議。 更新下載了新版本,在手動接受新協議之前我無法編譯任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.