Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Created May 5, 2016 15:14
Show Gist options
  • Save fernandoaleman/868b64cd60ab2d51ab24e7bf384da1ca to your computer and use it in GitHub Desktop.
Save fernandoaleman/868b64cd60ab2d51ab24e7bf384da1ca to your computer and use it in GitHub Desktop.
Fixing libv8 and therubyracer on Mac
brew tap homebrew/versions
brew install v8-315
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315
bundle install
@escoberik
Copy link

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 3.16.14.19

then run bundle install

Hope this helps!

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

@sergey-alekseev
Copy link

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

worked for me, thanks

@vinay-kumar-g-c42
Copy link

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

worked for me, thanks

@jlm
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 https://www.alfredapp.com/help/kb/python-2-monterey/), 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.

@johnAirRobe
Copy link

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
bundle

@gamesover
Copy link

if someone is using mini_racer 0.3.0 or below, please upgrade to gem 'mini_racer', '0.6.2' and comment out libv8

trust me, it will save you hours of dev config time

@srfinkel
Copy link

Much thanks @gamesover This was the perfect fix for Monterey 12.4 on a M1.

if someone is using mini_racer 0.3.0 or below, please upgrade to gem 'mini_racer', '0.6.2' and comment out libv8

trust me, it will save you hours of dev config time

@mrcsporto
Copy link

Still not working on Ruby@3.1 the only way out is reverting to ruby 3.0.4

@AteqEjaz
Copy link

AteqEjaz commented Oct 6, 2022

Comment out Following 2 Gems from Gemfile

1: g em 'libv8'
2: gem 'therubyracer'

Add following Gem

gem 'mini_racer'

bundle install

Should work as suggested by @srfinkel

@vinit-mudgundi
Copy link

Still not working on Ruby@3.1, any solutions??

@jotolo
Copy link

jotolo commented Jan 29, 2023

Not working on ruby@3.1 yet

@curve-jyothish
Copy link

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

Thanks. Worked for me too!

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