简体   繁体   English

升级到Snow Leopard后的MySQL gem问题

[英]MySQL gem problem after upgrading to Snow Leopard

Just upgraded to Snow Leopard. 刚升级到Snow Leopard。 After a lot messing around I managed to get MySQL up and running. 在经历了很多混乱之后,我设法让MySQL运行起来。

Now I'm trying to get my Rails environments to work. 现在我想让我的Rails环境工作。 For a project I'm using Rails 3.0.3 and Ruby 1.8.7 对于一个项目,我使用的是Rails 3.0.3和Ruby 1.8.7

I've installed the MySQL2 gem using the following command: 我使用以下命令安装了MySQL2 gem:

sudo gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

When I launch rails server I get the following error: 当我启动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

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/ 卸载/删除所有rvm,ruby和rails实例,然后按照本指南进行全新安装: http//www.cowboycoded.com/2010/12/04/setting-up-rails-3-on-mac-osx-雪豹纹10-6-4 /

And everything worked. 一切顺利。 Hoorah! Hoorah!

Also downgraded MySQL at one stage too so not sure if that had an affect on the final outcome or not. 也在一个阶段降级MySQL,所以不确定这是否会对最终结果产生影响。

I just went through something like this yesterday with some other gems after upgrading to Snow Leopard. 在升级到Snow Leopard之后,我昨天和其他一些宝石一起经历了这样的事情。 I got very similar errors because it was trying to use old 32bit libraries when SL was looking for 64bit versions. 我得到了非常相似的错误,因为当SL正在寻找64位版本时,它试图使用旧的32位库。 First, make sure you've installed the 64-bit version of MySQL, because you'll be using that now. 首先,确保您已经安装了64位版本的MySQL,因为您现在将使用它。

Then, the thing that got me: gem uninstall mysql2 然后,让我的东西:宝石卸载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. 事实证明我已经安装了两次gem并且Rails试图加载错误的(32位)版本,即使我在其他地方安装了正确的版本。

Also, when you install the mysql gem you may want to try 此外,当您安装mysql gem时,您可能想尝试

export ARCHFLAGS="-arch i386 -arch x86_64"

before you sudo gem install mysql2 在你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. 如果你没有在RVM的控制下重新编译Ruby,你就会想要这样做。 Prior to Snow Leopard they'd compile as i386 32bit apps. 在Snow Leopard之前,他们将编译为i386 32位应用程序。 Afterwards, they'll need to be x86 64bit. 之后,他们需要x86 64位。 So, using RVM do rvm uninstall on your Ruby 1.8.7, then rvm install again. 因此,使用RVM在Ruby 1.8.7上执行rvm uninstall ,然后rvm install You can check whether you need to do that by running rvm list : 您可以通过运行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. 当为Snow Leopard正确配置时,Ruby(1.8.7或1.9+)将为x86_64。

After that you can run gem pristine to rebuild all your gems. 之后,您可以运行gem pristine来重建所有宝石。 As part of that process it will rebuild the native drivers, which should recompile as x86_64 also. 作为该过程的一部分,它将重建本机驱动程序,它们也应该重新编译为x86_64。

Also, it's a good idea to keep your RVM relatively current. 此外,保持RVM相对最新也是一个好主意。 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. 最新的转发,今晚是v1.1.13,所以如果你的年龄较大,你可能想做rvm get head赶上它。

Useful commands to help diagnose things are: gem env and rvm info . 帮助诊断事物的有用命令是: gem envrvm 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. 我最近有一个类似的问题,当rails启动rails控制台或rails服务器时,导致“但错误的架构没有找到合适的映像”错误。

Running file on the associatd .dylib files, and the gem, generally returned either an applicable x86_64 version, or a universal which included it. 在关联的.dylib文件和gem上运行file通常会返回适用的x86_64版本或包含它的通用版本。 Eventually, I traced it back to the actual version of Ruby I was running. 最后,我追溯到我正在运行的Ruby的实际版本。 The /usr/bin/ruby executable itself was only i386 compatible. / usr / bin / ruby​​可执行文件本身只与i386兼容。 This was really a shocker, as I assumed the new xcode and osx 10.7 would have brought me a 64 bit ruby. 这真是令人震惊,因为我认为新的xcode和osx 10.7会给我带来64位红宝石。

Using RVM, I installed another instance of ruby (again 1.8.7). 使用RVM,我安装了另一个ruby实例(同样是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/ . 这样做需要我安装一个新的readline实例(我使用自制软件, brew install readline )并使用rvm install 1.8.7 --with-readline-dir=/usr/local/Cellar/readline/6.2.1/安装rvm 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. 执行此操作后,切换到使用我的新ruby实例( rvm use 1.8.7 ),我的所有宝石都消失了(RVM安装以某种方式改变了我的默认gem_path。) gem install rake ,然后是gem install bundler ,然后是bundle install让我起来跑步。

Long story short, make sure your ruby executable matches the instruction-set version that your ruby/rails packages are were built in. 简而言之,请确保您的ruby可执行文件与您的ruby / rails软件包内置的指令集版本相匹配。

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/ 这篇博文也非常有用: http//www.markhneedham.com/blog/2010/07/08/installing-ruby-1-9-2-with-rvm-on-snow-leopard/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM