Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fixing libv8 and therubyracer on Mac
brew tap homebrew/versions
brew install v8-315
gem install libv8 -v '' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315
bundle install
Copy link

eveevans commented Jan 11, 2022

@chrishough you will need brew, but the thing about it, is that there are two versions of homebrew for Silicon macs, the one for ARM (by default), and the one for Intel (which needs to be run under Rosetta)

In the time I installed Ruby there were a lot of Brew package unavailable for ARM. So I used the Intel version (X86) in order to install the X86 version of ASDF, using X86 dependencies

(In my case, I was using and old Ruby that needed old dependencies)

Copy link

chrishough commented Jan 11, 2022

@eveevans I am having this issue on both an M1 and non-m1 machine, trying to fix the non-m1 first

Copy link

redferret commented Jan 12, 2022

I worked on this work around. It worked for me and I've never had any issues.
It's kinda long but a Turing instructor and I worked on this.
One of the answers in the answers also might work too

Copy link

barracuda156 commented Jan 29, 2022

Has someone been able to build libv8 on a PowerPC Mac?

Copy link

BDanyil commented Feb 9, 2022

bundle config build.libv8 --with-system-v8
bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8@3.15)

Worked on MacBook Pro 2020

Copy link

artoodeeto commented Feb 19, 2022

@BDanyil are you running macos monterey 12.2 on intel? i tried following the installing but its not working for monterey. thank you for your response

Copy link

artoodeeto commented Feb 19, 2022

is anyone able to run this on macos intel monterey 12.2.1? im getting an error:

Screen Shot 2022-02-19 at 1 40 42 AM

please help. thank you. I really appreciate it.

Copy link

channainfo commented Mar 8, 2022

Still works just fine with my env Catalina, Ruby 2.6.6, and Rails

Copy link

robbyrussell commented Mar 15, 2022

On my Apple M1 with MySQL 5.7 and OpenSSL@1.1 with Ruby 2.6.5.x

    bundle config build.mysql2

   bundle install  # installed mysql2 with native gems just fine  

Copy link

erik-escobedo commented Mar 15, 2022

After hours of dealing with this, I finally found a solution that worked for me. Big Sur 11.6 - Intel

env \ CXX=clang++ \ GYPFLAGS=-Dmac_deployment_target=10.9 \ gem install libv8 --version

then run bundle install

Hope this helps!

This one worked for me as well! Thank you very much

Copy link

sergey-alekseev commented Mar 27, 2022

bundle config build.libv8 --with-system-v8
bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8@3.15)

worked for me, thanks

Copy link

vinay-kumar-g-c42 commented Apr 18, 2022

bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8@3.15)

worked for me, thanks

Copy link

jlm commented May 3, 2022

macOS Monterey doesn't include Python 2 anymore. Python 2 is required by libv8. To install it (from, execute the following (preferably in a new shell because it changes $PATH):

export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"
eval "$(brew shellenv)"
brew install pyenv
pyenv install 2.7.18
ln -s "${HOME}/.pyenv/versions/2.7.18/bin/python2.7" "${HOMEBREW_PREFIX}/bin/python"

For Ruby 3.0.4 in Monterey (macOS 12.3.1), this worked for me:

brew install v8@3.15
bundle config build.libv8 --with-system-v8
bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8@3.15)
bundle install

Unfortunately, it's not so easy in Ruby. 3.1. That includes psych-4 as a "default" (hard-coded in) gem which can't be removed, and psych-4 is incompatible with libv8 (for now at least). I have not found a solution to this, aside from reverting to ruby 3.0.4.

Copy link

johnAirRobe commented Jun 24, 2022

For those who any of the above fixes didn't work I installed Python 3.9.1 set it to the global python version (setting it to local version didn't work), and ran bundle again and it installed mini_racer correctly.

What tipped me off was the following message in the console output after it failed:

Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.spawn import find_executable
Please use python3.9 or python3.8 or python3.7 or python3.6 or python3.5 or python2.7.
Node.js configure: Found Python 3.10.2...

Here are the commands I ran:

pyenv install 3.9.1
pyenv global 3.9.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment