2012-02-01 66 views
1

我已經安裝了rails,mysql2 gem和mysql,並使用rails new simple_cms -d mysql創建了一個名爲simple_cms的項目。現在,當我執行rails server開始WEBricks,我得到快樂的這桶:rails server命令無法找到庫

/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib (LoadError) 
    Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle 
    Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle 
    from /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2.rb:9 
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require' 
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require' 
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each' 
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `require' 
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each' 
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require' 
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.21/lib/bundler.rb:122:in `require' 
    from /Users/tyre77/Dropbox/Broetry In Motion/RailsTestApp/simple_cms/config/application.rb:7 
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.1/lib/rails/commands.rb:53:in `require' 
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.1/lib/rails/commands.rb:53 
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap' 
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.1/lib/rails/commands.rb:50 
    from script/rails:6:in `require' 
    from script/rails:6 

我已經改變了我的.bash_profile看起來像這樣:(不知道如果相關)

PS1="\u \w$ " 
alias ll="ls -lahG" 

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/$PATH" 


# include .bashrc if it exists 
if [ -f $HOME/.bashrc ]; then 
    . $HOME/.bashrc 
fi 

# startup virtualenv-burrito 
if [ -f $HOME/.venvburrito/startup.sh ]; then 
    . $HOME/.venvburrito/startup.sh 
fi 

參見: Unable to start rails server但我的mysql版本是不同的,並沒有解決它即使改變0.2.6到0.3.11

+0

你是如何安裝MySQL的?另外,你爲什麼使用Apple的Ruby代替RVM或rbenv? – 2012-02-01 22:56:32

+0

@MaurícioLinhares我通過dev.mysql.com安裝了它並使用了DMG。 – Chris 2012-02-02 06:37:44

+0

@MaurícioLinhares爲什麼我不使用內置的Ruby? – Chris 2012-02-02 06:38:15

回答

2

問題是,Ruby找不到建立MySQL gem所需的庫,有很多方法解決這個問題,但sinc e它看起來像你剛剛開始使用Ruby,我認爲這是值得準備你的環境,所以你不會再看到這種東西,這裏是步驟:

首先,我會建議你安裝Homebrew ,安裝自制軟件,安裝MySQL:

brew install mysql 

這將在您的機器包括必要的庫來構建MySQL的寶石,當你需要它安裝MySQL。

然後您應該安裝RVM來安裝您的紅寶石(在安裝RVM之前,您需要運行brew安裝git)。一旦你安裝了RVM,你可以開始安裝你想要的任何紅寶石。

然後你問,爲什麼你不能使用內置的Ruby? Rails將在4.0上支持Ruby 1.8。*分支,而社區通常使用RVM(或rbenv)來安裝和管理安裝到您計算機上的ruby。

+0

太棒了!那麼像virtualenv這樣的自制軟件?如果我已經下載了mysql DMG,是否需要再次執行(聽起來像我需要tar)? – Chris 2012-02-02 14:35:28

+0

刪除你完全安裝的MySQL,並讓它與自制軟件一起安裝。 ** RVM **接近virtualenv。 – 2012-02-02 15:43:33