10
votes

I have serious problem with Ruby and OSX Lion - whenever I try to start Rails or even a rake tool I am getting this error:

[FATAL] failed to allocate memory

I tried recompilling ruby in different versions (1.9.2-p180, 1.9.2-p290, 1.9.2-head) and its always the same.

However I noticed that I can remove some gems and then "rake" tool will work and only 'rails s' will die with that error. It seems like there is in fact not enough memory for this amount of gems I am using, but again this seems very weird - it works perfectly fine on Snow Leopard and even at my company on mac mini with Lion - the only difference is that the mini is upgraded Snow Leopard -> Lion, whilst on my iMac its a clean Lion installation.

Any ideas? Is there a setting of some kind to increase memory on OSX/Lion?

3

3 Answers

7
votes

It took me some time to figure it out but here is the solution:

This problem was caused by mysql2 gem, when I switched to ruby-mysql it all started working again (remember to change adapter from mysql2 to mysql in your database.yml!)

So I started thinking about differences between mac mini and iMac. Basically the mini is running Lion upgraded from Snow Leopard, which is upgraded Leopard and it has good, old Mac Ports for mysql and pgsql servers. So when gem is compiled its using port libraries.

On the other hand the iMac with fresh Lion installation has Zend Server package (apache + php + mysql binaries) and a Homebrew package 'mysql-connector-c' that has libraries needed to compile gem.

All in all it seems as if ports version of mysql works correctly whereas Homewbrew connector does not (its leaking some memory?).

Hope this helps.

4
votes

I uninstalled mysql2

$ gem uninstall mysql2

And reinstalled via bundler

$ bundle

And I'm able to rails s once again

3
votes

I had a conflicting package mysql-connector-c from homebrew installed. mysql2 used the dylib from this package and not from the mysql install. Removing the homebrew package yielded another problem, which could be solved by adding

export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/"

to my environment.