新手警报......
尝试修复我的rails webrick服务器的问题(即启动它),我使用旧的Stackoverflow回答old answer并执行以下命令
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
但是,我忘了更改版本号。例如,我的mysql是0.3.6(而不是命令中的0.2.6),它也是libmysqlclient.18而不是.16。
现在,当我尝试启动rails服务器时,它说
Could not find gem 'mysql2 (~> 0.2.6)' in any of the gem sources listed in your Gemfile.
我尝试用更新的版本重新运行此命令,但它没有改变任何东西......的确,它甚至没有问我的root密码......我有什么想法可以解决这个问题吗?
更新 - 这是我gem list
时生成的宝石列表。回答这个问题的第一个人建议(在他的评论中)我卸载了mysql .0.2.6但是从未安装过gem。当我执行上面描述的name_tool命令时,它告诉系统查找mysql 0.2.6,当我应该告诉它寻找mysql2-0.3.6时。
abstract (1.0.0)
actionmailer (3.0.9, 3.0.7)
actionpack (3.0.9, 3.0.7)
activemodel (3.0.9, 3.0.7)
activerecord (3.0.9, 3.0.7)
activeresource (3.0.9, 3.0.7)
activesupport (3.0.9, 3.0.7)
arel (2.0.10)
builder (2.1.2)
bundler (1.0.14)
erubis (2.6.6)
i18n (0.5.0)
mail (2.2.19)
mime-types (1.16)
mysql2 (0.3.6)
polyglot (0.3.1)
rack (1.2.3)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.9, 3.0.7)
railties (3.0.9, 3.0.7)
rake (0.9.1)
rdoc (3.8)
rubygems-update (1.8.5)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.27)
更新 - 按照Eric Hu的回答中的说明,当我从项目文件夹中运行rails server
时,我得到了这个结果
2011-07-26 01:49:17 rails s
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.11/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.11/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.11/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.11/lib/mysql2/mysql2.bundle
from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.11/lib/mysql2.rb:9
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler.rb:120:in `require'
from /Users/michaelmitchell/Sites/simple_cms/config/application.rb:7
from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:28:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:28
from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
更新 - 我在他的评论
中提到了捆绑列表Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.9)
* actionpack (3.0.9)
* activemodel (3.0.9)
* activerecord (3.0.9)
* activeresource (3.0.9)
* activesupport (3.0.9)
* arel (2.0.10)
* builder (2.1.2)
* bundler (1.0.14)
* erubis (2.6.6)
* i18n (0.5.0)
* mail (2.2.19)
* mime-types (1.16)
* mysql2 (0.2.11)
* polyglot (0.3.1)
* rack (1.2.3)
* rack-mount (0.6.14)
* rack-test (0.5.7)
* rails (3.0.9)
* railties (3.0.9)
* rake (0.9.2)
* rdoc (3.8)
* thor (0.14.6)
* treetop (1.4.9)
* tzinfo (0.3.29)
答案 0 :(得分:3)
我相信你在使用bundler
和RubyGems方面遇到了困惑。当您gem install <gemname>
时,您正在使用RubyGems命令安装最新版本的<gemname>
。
Rails项目附带了一个名为bundler
的宝石,它也可以管理宝石。 Bundler为您为其创建Gemfile的每个Rails项目构建单独的gems副本。如果您不记得制作Gemfile,那是因为它是rails new <projectname>
将为您生成的文件之一。
最有可能的是,您还没有运行bundle install
。在此之前,请转到当前Rails项目的文件夹并打开Gemfile
,以便您知道发生了什么。我愿意打赌这里有一条线:gem 'mysql2', '~> 0.2.6'
要安装正确的版本,请转到命令行中的项目文件夹。输入bundle install
。给它一分钟,应该是它 - 尝试再次运行rails s
。
如果这看起来令人困惑和不必要,请记住,当有人更新宝石时,他们可能会以破坏程序的方式进行更改。 Bundler通过确保您的程序运行所需的特定版本的gem(在这种情况下,mysql2-0.2.6而不是mysql2-0.3.6)来为您提供服务。
答案 1 :(得分:0)
清理掉那颗宝石并重新安装。
或者,用于MySQL安装的RVM + Mac Homebrew可以创造奇迹。