OSX, RubyGems and cross-thread violations in rb_gc
I recently decided to migrate away from OSX’s default ruby install yesterday and noticed a few quirky hangups. Firstly, for some reason, and I’m not sure if it is just me or not, OSX’s default $PATH variable is putting /usr/local/bin AFTER /bin making your local installs not enabled by default. (Editing the /etc/paths didn’t do the trick so I manually added it to PATH).
The installation went easily for both ruby gems and ruby, but I decided to take a ’short cut’ and copy all my gems from /Library/Ruby/Gems into my /usr/local/lib directory which started raising all kinds of errors — this one, in particular was obnoxious.
[BUG] cross-thread violation on rb_gc()
Luckily, all that means is that I copied over gems which were compiled against the standard OSX ruby version and not the new one. This was a little script I wrote which will show you which gems need to be re-compiled. Just cd over to your /usr/local/lib/ruby/gems/1.8/gems directory and run:
gems $>ls -1 **/**/*.bundle|ruby -pe '$_.gsub! /\-.*/, ""'|uniq
to get a list, or pipe that into $> sudo gem install and that should clear up those gc issues.







Lance June 1st
thanks man, this really helped me out.
Cheers
shyam July 13th
I get following errors while going through your insrtuction:
gems $ ls -1 **/**/*.bundle|ruby -pe ‘$_.gsub! /\-.*/, “”‘|uniq
-e:1: Invalid char `\342′ in expression
-e:1: Invalid char `\200′ in expression
-e:1: Invalid char `\230′ in expression
-e:1: syntax error, unexpected ‘.’
‘.gsub!
^
Please suggest me
Rolf Bjaanes July 31st
try this instead to find all the gems:
ruby -rubygems -e ‘p Gem.source_index.find_all { |n,s| !s.extensions.empty? }.map { |n,s| [s.name, s.version.to_s] }’
Xavier Shay August 4th
to pipe it you need xargs:
ls -1 **/**/*.bundle|ruby -pe ‘$_.gsub! /\-.*/, “”‘|uniq | xargs sudo gem install
if you’re in a rush, you can speed it up a bit by passing –no-rdoc and –no-ri options to gem install.
Eric Lubow July 7th
This was really helpful. Saved me what would likely have been hours. Thanks.
Simon September 26th
Thanks, the command of Rolf worked for me (just be careful with your CMS, it changes the normal quotes to smart quotes, Terminal doesn’t like those).
Pete Campbell July 28th
Good explanation, but you might want to mention that the offending Gem(s) may also be in vendor/gems or vendor/cache (with Bundler). http://petecampbell.wordpress.com/2011/07/28/cross-thread-violations-on-rb_gc-vendored-gems-eek/
Add Yours
YOU