If you have received the following error when running gem install therubyracer -v '0.12.3' -- --with-v8-dir=$(brew --prefix v8)
:
Building native extensions with: '--with-v8-dir=/opt/homebrew/opt/v8' This could take a while... ERROR: Error installing therubyracer: ERROR: Failed to build gem native extension.
current directory: /Users/surya/.rvm/gems/ruby-2.6.6@rails602/gems/therubyracer-0.12.3/ext/v8
/Users/surya/.rvm/rubies/ruby-2.6.6/bin/ruby -I /Users/surya/.rvm/rubies/ruby-2.6.6/lib/ruby/site_ruby/2.6.0 -r ./siteconf20220124-21151-13m9cq6.rb extconf.rb --with-v8-dir=/opt/homebrew/opt/v8 checking for -lpthread... yes checking for -lobjc... yes checking for v8.h... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
Provided configuration options: --with-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/Users/surya/.rvm/rubies/ruby-2.6.6/bin/$(RUBY_BASE_NAME) --with-pthreadlib --without-pthreadlib --with-objclib --without-objclib --enable-debug --disable-debug --with-v8-dir --with-v8-include --without-v8-include=${v8-dir}/include --with-v8-lib --without-v8-lib=${v8-dir}/lib /Users/surya/.rvm/gems/ruby-2.6.6@rails602/gems/libv8-3.16.14.19/ext/libv8/location.rb:50:in `configure': By using --with-system-v8, you have chosen to use the version (Libv8::Location::System::NotFoundError) of V8 found on your system and not the one that is bundled with the libv8 rubygem.
However, your system version of v8 could not be located.
Please make sure your system version of v8 that is compatible with 3.16.14.19 installed. You may need to use the --with-v8-dir option if it is installed in a non-standard location from /Users/surya/.rvm/gems/ruby-2.6.6@rails602/gems/libv8-3.16.14.19/lib/libv8.rb:7:in
'configure_makefile' from extconf.rb:32:in
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/surya/.rvm/gems/ruby-2.6.6@rails602/extensions/-darwin-21/2.6.0/therubyracer-0.12.3/mkmf.log
extconf failed, exit code 1
You should abe able to fix it using Rosetta. Read this comment on a gist.
I will summerize the steps here:
Install brew for ARM -
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install brew for Intel (via Rosseta 2)-
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
You may add an alias for it in your shell rc(.bashrc or .zshrc) file:
alias brew86="arch -x86_64 /usr/local/homebrew/bin/brew"
Post his install libv8 and therubyracer:
gem install libv8 -v '3.16.14.19' -- --with-system-v8
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/Homebrew/opt/[email protected]
Now, you can run:
bundle install