升级到Snow Leopard后MySQL gem问题
刚刚升级到雪豹。经过一番折腾后,我设法让 MySQL 启动并运行。
现在我正在尝试让我的 Rails 环境正常工作。对于我使用 Rails 3.0.3 和 Ruby 1.8.7 的项目,
我使用以下命令安装了 MySQL2 gem:
sudo gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
当我启动 Rails 服务器时,出现以下错误:
/Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): no suitable image found. Did find: (LoadError)
/Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: mach-o, but wrong architecture - /Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
from /Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2.rb:7
有没有人经历过类似的问题并且知道如何解决这个问题? 我更像是一名设计师而不是开发人员,所以这不是我的强项。感谢任何指点。
Just upgraded to Snow Leopard. After a lot messing around I managed to get MySQL up and running.
Now I'm trying to get my Rails environments to work. For a project I'm using Rails 3.0.3 and Ruby 1.8.7
I've installed the MySQL2 gem using the following command:
sudo gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
When I launch rails server I get the following error:
/Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): no suitable image found. Did find: (LoadError)
/Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: mach-o, but wrong architecture - /Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
from /Users/lee/.rvm/gems/ruby-1.8.7-head/gems/mysql2-0.2.6/lib/mysql2.rb:7
Has any one experienced a similar problem and know how to fix this?
I'm more a designer than developer so this wouldn't be my strong area. Appreciate any pointers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
卸载/删除 RVM、Ruby 和 Rails 的所有实例,然后按照本指南进行全新安装:
http://www.cowboycoded.com/2010/12/04/setting-up-rails-3-on-mac-osx-snow-leopard-10-6-4/
一切正常。万岁!
还一度降级了 MySQL,所以不确定这是否对最终结果有影响。
Uninstalled/removed all instances of rvm, ruby and rails then did a clean install following this guide:
http://www.cowboycoded.com/2010/12/04/setting-up-rails-3-on-mac-osx-snow-leopard-10-6-4/
And everything worked. Hoorah!
Also downgraded MySQL at one stage too so not sure if that had an affect on the final outcome or not.
升级到 Snow Leopard 后,我昨天刚刚与其他一些宝石经历了类似的事情。我遇到了非常类似的错误,因为当 SL 寻找 64 位版本时,它试图使用旧的 32 位库。首先,确保您已经安装了 64 位版本的 MySQL,因为您现在将使用它。
然后,让我困惑的是: gem uninstall mysql2
结果我安装了两次 gem,并且 Rails 试图加载错误的(32 位)版本,即使我在其他地方安装了正确的版本。
另外,当您安装 mysql gem 时,您可能需要
在 sudo gem install mysql2 之前尝试一下
I just went through something like this yesterday with some other gems after upgrading to Snow Leopard. I got very similar errors because it was trying to use old 32bit libraries when SL was looking for 64bit versions. First, make sure you've installed the 64-bit version of MySQL, because you'll be using that now.
Then, the thing that got me: gem uninstall mysql2
Turns out I had the gem installed twice and Rails was trying to load the wrong (32bit) version even though I had the correct one installed elsewhere.
Also, when you install the mysql gem you may want to try
before you sudo gem install mysql2
有几件事要做:
如果您没有在 RVM 的控制下重新编译 Ruby,那么您将需要这样做。在 Snow Leopard 之前,它们会编译为 i386 32 位应用程序。之后,它们需要是 x86 64 位。因此,使用 RVM 在 Ruby 1.8.7 上执行
rvm uninstall
,然后再次rvm install
。您可以通过运行rvm list
来检查是否需要执行此操作:为 Snow Leopard 正确配置后,Ruby(1.8.7 或 1.9+)将是 x86_64。
之后,您可以运行
gem pristine
来重建所有gems。作为该过程的一部分,它将重建本机驱动程序,该驱动程序也应该重新编译为 x86_64。此外,保持 RVM 相对最新也是一个好主意。截至今晚,最新版本是 v1.1.13,因此如果您的版本较旧,您可能需要执行
rvm get head
来赶上它。帮助诊断的有用命令是:gem env 和 rvm info。
There are a couple things to do:
If you didn't recompile the Ruby's under RVM's control, you'll want to do that. Prior to Snow Leopard they'd compile as i386 32bit apps. Afterwards, they'll need to be x86 64bit. So, using RVM do
rvm uninstall
on your Ruby 1.8.7, thenrvm install
again. You can check whether you need to do that by runningrvm list
:Ruby, either 1.8.7 or 1.9+, will be x86_64 when configured correctly for Snow Leopard.
After that you can run
gem pristine
to rebuild all your gems. As part of that process it will rebuild the native drivers, which should recompile as x86_64 also.Also, it's a good idea to keep your RVM relatively current. The latest rev, as of tonight, is v1.1.13, so if yours is older you might want to do
rvm get head
to catch it up.Useful commands to help diagnose things are:
gem env
andrvm info
.我最近遇到了一个类似的问题,在启动 Rails 控制台或 Rails 服务器时,Rails 抛出“但错误的架构,没有找到合适的图像”错误。
在关联的 .dylib 文件和 gem 上运行
file
通常会返回适用的 x86_64 版本或包含该版本的通用版本。最终,我追溯到了我运行的实际 Ruby 版本。 /usr/bin/ruby 可执行文件本身仅兼容 i386。这确实令人震惊,因为我以为新的 xcode 和 osx 10.7 会给我带来 64 位 ruby。使用 RVM,我安装了另一个 ruby 实例(同样是 1.8.7)。执行此操作需要我安装一个新的 readline 实例(我使用自制程序:brew install readline)并使用 rvm install 1.8.7 --with-readline-dir 安装 rvm =/usr/local/Cellar/readline/6.2.1/。
完成此操作后,并切换到使用我的新 ruby 实例(
rvm use 1.8.7
),我所有的 gem 都消失了(RVM 安装以某种方式更改了我的默认 gem_path。)gem install rake< /code>,然后是
gem install bundler
,然后是bundle install
让我启动并运行。长话短说,确保您的 ruby 可执行文件与您的 ruby/rails 包内置的指令集版本相匹配。
这篇博客文章也非常有帮助:
http://www.markhneedham.com/blog/2010/07/08/installing-ruby-1-9-2-with-rvm-on-snow-leopard/
I recently had a similar issue where rails was throwing the "but wrong architecture no suitable image found" error when starting rails console or the rails server.
Running
file
on the associatd .dylib files, and the gem, generally returned either an applicable x86_64 version, or a universal which included it. Eventually, I traced it back to the actual version of Ruby I was running. The /usr/bin/ruby executable itself was only i386 compatible. This was really a shocker, as I assumed the new xcode and osx 10.7 would have brought me a 64 bit ruby.Using RVM, I installed another instance of ruby (again 1.8.7). Doing this required that I install a new instance of readline (for which I used homebrew, :
brew install readline
) and installed the rvm withrvm install 1.8.7 --with-readline-dir=/usr/local/Cellar/readline/6.2.1/
.After doing this, and switching to use my new ruby instance (
rvm use 1.8.7
), all my gems were gone (the RVM install somehow changed my default gem_path.)gem install rake
, followed bygem install bundler
, and thenbundle install
got me up and running.Long story short, make sure your ruby executable matches the instruction-set version that your ruby/rails packages are were built in.
This blog post was quite helpful as well:
http://www.markhneedham.com/blog/2010/07/08/installing-ruby-1-9-2-with-rvm-on-snow-leopard/