Search code examples
ruby-on-railsrubygemsapple-m1therubyracerlibv8

therubyracer no suitable image found mach-o, but wrong architecture


I'm getting setup with ruby on rails on my new Apple Silicon machine in regards to getting v8 and therubyracer installed correctly. As abundantly documented, there are a few issues I'm working through to be able to execute basic rails commands.

I've been using this Github thread as my reference point. I installed [email protected] with the arch -x86_64 to use the Homebrew installed on the Rosetta Terminal. After which I installed the specific gems I needed:

arch -x86_64 gem install libv8 -v '3.16.14.19' -- --with-system-v8 
arch -x86_64 gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/[email protected]

After which I return to my regular Terminal. I then run bundle install and then rails s (or any rails command) and I see the following error:

dlopen(/Users/myuser/.rvm/gems/ruby-2.6.3@myproject/gems/therubyracer-0.12.3/lib/v8/init.bundle, 9): no suitable image found.  Did find: (LoadError)
    /Users/myuser/.rvm/gems/ruby-2.6.3@myproject/gems/therubyracer-0.12.3/lib/v8/init.bundle: mach-o, but wrong architecture
    /Users/myuser/.rvm/gems/ruby-2.6.3@myproject/gems/therubyracer-0.12.3/lib/v8/init.bundle: mach-o, but wrong architecture - /Users/myuser/.rvm/gems/ruby-2.6.3@myproject/gems/therubyracer-0.12.3/lib/v8/init.bundle

I see the same error if I ran it from the Rosetta Terminal. I haven't found anything that gets me closer to diagnosing this error. It's tough because if I install those same gems without the arch -x86_64, I'll see a set of errors described here.

I have two versions of Homebrew: one linked to the Rosetta Terminal, and one for native Apple Silicon. I've been careful to use the Rosetta Terminal Homebrew to install v8 and the native Apple Silicon Homebrew for everything else.

Your time and energy is greatly appreciated. I'd be more than happy to provide more context as necessary. Thank you.


Solution

  • The way I ended up resolving this issue was simply to not use therubyracer. It's a rather unsatisfying answer, but I think avoiding this gem if possible is the best way to go.