2011-04-15 212 views
1

我到處搜索過,沒有任何解決方案可以解決我的問題。我已經使用SQLite構建rails應用程序,但不是MySQL。對於這個特定的項目,我需要MySQL。當我嘗試啓動服務器時出現錯誤,所以我嘗試安裝MySQL的gems並得到另一個錯誤。有沒有人有任何見解?謝謝!Ruby On Rails上的MySQL Gem

rails server 
    Could not find gem 'mysql2 (>= 0)' in any of the gem sources listed in your Gemfile. 

    sudo gem install mysql2 
    Building native extensions. This could take a while... 
    ERROR: Error installing mysql2: 
     ERROR: Failed to build gem native extension. 

      /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 


    Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7 for inspection. 
    Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/ext/mysql2/gem_make.out 
+0

看起來你正在運行OSX ......哪個版本?你是否爲你的OSX版本安裝了開發工具(Xcode)? – brettish 2011-04-15 21:16:00

+0

你是如何在你的os x機器上安裝mysql的? – Wes 2011-04-15 21:37:24

+0

OS X應該已經安裝了MySQL ...但您也可以從[MySQL網站](http://www.mysql.com/downloads/mysql/)下載二進制文件。 – brettish 2011-04-15 21:53:38

回答

3

我有這個問題。您需要使用本機擴展來安裝mysql gem。

你可能尋找的線路是這樣的:

$ ARCHFLAGS="-arch x86_64" gem install mysql2 --version '~> 0.2.7' -- --with-mysql-config=/usr/local/mysql/bin/mysql_config 

全部寫上去得到它打算在這裏:http://softwaregravy.com/mysql-on-os-x-rails-3-0-7/