2015-07-01 82 views
1

出於某種原因,我在安裝MySQL gem時遇到問題,而過去並不是這樣。我嘗試過一些沒有成功的東西。如:在Rails 4中安裝MySQL gem時出錯

將源'https://rubygems.org'更改爲源'http://rubygems.org'

也安裝gem install mysql

以及sudo apt-get install mysql-dev然後gem install mysql

這是錯誤:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    /home/kaka/.rbenv/versions/2.2.2/bin/ruby -r ./siteconf20150701-13627-kzmz5m.rb extconf.rb 
checking for ruby/thread.h... yes 
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes 
checking for rb_thread_blocking_region()... no 
checking for rb_wait_for_single_fd()... yes 
checking for rb_hash_dup()... yes 
checking for rb_intern3()... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lm... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lz... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lsocket... no 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lnsl... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lmygcc... no 
checking for mysql_query() in -lmysqlclient... no 
*** 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=/home/kaka/.rbenv/versions/2.2.2/bin/$(RUBY_BASE_NAME) 
    --with-mysql-dir 
    --without-mysql-dir 
    --with-mysql-include 
    --without-mysql-include=${mysql-dir}/include 
    --with-mysql-lib 
    --without-mysql-lib=${mysql-dir}/lib 
    --with-mysql-config 
    --without-mysql-config 
    --with-mysql-dir 
    --without-mysql-dir 
    --with-mysql-include 
    --without-mysql-include=${mysql-dir}/include 
    --with-mysql-lib 
    --without-mysql-lib=${mysql-dir}/lib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-mlib 
    --without-mlib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-zlib 
    --without-zlib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-socketlib 
    --without-socketlib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-nsllib 
    --without-nsllib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-mygcclib 
    --without-mygcclib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 

extconf failed, exit code 1 

Gem files will remain installed in /home/kaka/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18 for inspection. 
Results logged to /home/kaka/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/mysql2-0.3.18/gem_make.out 
An error occurred while installing mysql2 (0.3.18), and Bundler cannot continue. 
Make sure that `gem install mysql2 -v '0.3.18'` succeeds before bundling. 

誰能幫助我?

我應該先安裝mySQL服務器來安裝這個gem嗎?

+0

您是否試過'sudo gem install mysql2 -v'0.3.18'' – Abhi

+0

試試'gem install mysql2' –

+0

當我執行sudo gem install mysql2 -v'0.3.18'我得到了sudo:gem:command not found – kaka

回答

0

第一安裝MySQL客戶端/服務器: 命令和apt-get安裝的MySQL服務器的libmysqlclient-dev的MySQL的客戶端libmysqld-dev的mysql的常見

0

答案很簡單: brew install mysql && bundle

長的答案

我沒有安裝正確的mysql時遇到此錯誤。我決定去看看那裏的MySQL是如此,我跑

$ which mysql 
mysql: aliased to nocorrect mysql 

後來我做了一些搜索,發現type mysql是一種更好的方式來做到這一點,因爲它會告訴我,上面的錯誤是特定問題,即zsh的別名的mysql到'正確的MySQL'。

無論如何,以爲我沒有MySQL我運行brew install mysql和rebundled哪些固定的問題。所以問題解決了,但如果我運行which mysql它仍然響應'正確的mysql'。所以今天的教訓是使用類型而不是其中的一種。還要在安裝gem之前安裝mysql。