How to Install (Or Get Rid Of) therubyracer on M1 or M2 Macs

Updated

UPDATE: An updated version of this post now lives on the Ruby on Mac blog

If you’ve been banging your head against a wall trying to install therubyracer gem on an Apple Silicon Mac (M1 or M2), then you’ve come to the right place.

From talking to Ruby on Mac customers and other Ruby developers, a common pain point is not being able to run legacy Rails apps on M1 Macs. This is due to the projects using old versions of Ruby, and old versions of gems that might not be maintained anymore and that aren’t supported on the M1/M2 chip.

The gem most people complain about is therubyracer. They spend days trying to install it, and either end up giving up or using workarounds they’re not happy with. The reason why you can’t install it natively is because it hasn’t been updated to support the ARM architecture that the Apple Silicon chips use. If you look it up in rubygems.org, you’ll see that it hasn’t been updated since January 5, 2017.

Instead, I recommend replacing therubyracer or eliminating it entirely. In many cases, one of these 3 solutions should work:

Another popular gem that gives people trouble on M1 macs is ffi, and the most common reason is using an older version of the gem. The general rule of thumb is to update any gem that is the source of the error in the stacktrace. Updating gems to their latest version resolves most issues with old projects on Apple Silicon Macs.

If you’re still stuck getting your old Ruby projects to run, you can hire me and I’d be happy to help you. I’m taking on a limited number of clients at this time. Feel free to email me at my first name @ rubyonmac.dev and we’ll go from there.