MySQL gem problem after upgrading to Snow Leopard
Just upgraded to Snow Leopard. After a lot messing around I m开发者_JAVA技巧anaged 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.
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.
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
export ARCHFLAGS="-arch i386 -arch x86_64"
before you sudo gem install mysql2
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, then rvm install
again. You can check whether you need to do that by running rvm list
:
rvm list
rvm rubies
ruby-1.8.7-p330 [ x86_64 ]
=> ruby-1.9.2-p136 [ x86_64 ]
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
and rvm info
.
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 with rvm 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 by gem install bundler
, and then bundle 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/
精彩评论