2

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 v8@3.15 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/v8@3.15

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.

Atticus
  • 418
  • 2
  • 6
  • 20
  • Are you sure you really need the therubyracer or libv8? therubyracer is not actually needed for the assets pipeline in modern versions of Rails and its easier to just install Node for a JS runtime. Heroku for example discourages the use of therubyracer as its a memory hog. – max Aug 15 '21 at 20:06
  • Probably don't need therubyracer, but moving away from it is not a priority at the moment. Thanks for pointing out the bit about Heroku. – Atticus Aug 17 '21 at 01:19
  • @Atticus try [this](https://gist.github.com/fernandoaleman/868b64cd60ab2d51ab24e7bf384da1ca). – Chandan Aug 17 '21 at 17:06
  • @Chandan I have but to no avail. – Atticus Aug 17 '21 at 17:12

1 Answers1

0

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.

Atticus
  • 418
  • 2
  • 6
  • 20
  • Same. Moved to `mini_racer`, which so far has Just Worked (also doesn't require the hacky arch install for v8) – wbharding Dec 11 '21 at 23:04