Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@acwio
Copy link

acwio commented Jul 7, 2021

Confirming that :

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

worked for me. Big Sur. 2020 MacBook.

@andreydro
Copy link

andreydro commented Jul 8, 2021

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

Thanks to acwio. Worked for me. Big Sure. 2020 Macbook

@steady-daddy
Copy link

steady-daddy commented Jul 21, 2021

Happy to report that the following still works for ruby 2.7.0:

brew install v8@3.15

gem install libv8 -v 3.16.14.19 -- --with-system-v8

gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8@3.15

This worked for me with Ruby 2.6.6. Thank you so much for sharing.

@bharathEN
Copy link

bharathEN commented Jul 30, 2021

@kenn

For bundler I did the following on Catalina

$ 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

Worked perfectly!! For ruby 2.6.5 :D

Works perfect on BigSur

@dp21g
Copy link

dp21g commented Sep 15, 2021

If it still doesn't work then try deleting the gemset and create it again. That worked for me. replace my_engine with the name of your project.

rvm gemset delete my_engine
rvm gemset create my_engine
sudo gem install bundler
bundle install

@kenn
Copy link

kenn commented Sep 15, 2021

@bharathEN please don't mention my name, it adds me to this thread every time.

@jsonjunkie
Copy link

jsonjunkie commented Sep 29, 2021

Got it to work, tho homebrew/versions is no longer necessary and the flag is now --with-v8-dir=/usr/local/opt/v8@3.15 due to change of folder versioning.

Same as @gurdiga above ^

@simshanith installing therubyracer gem using this different flag worked for me using ruby 2.6.5 and therubyracer 0.12.3 after installing libv8 v3.16.14.19 with the "--with-system-v8" flag. now running into issues that i don't think are relevant to this thread

@manish3499
Copy link

manish3499 commented Oct 1, 2021

After days of dealing with this I finally found the solution. First of all, there is no bottle for v8@3.15 for ARM yet. So you have to install it via Rosseta 2.

This is the tricky part, because if you install brew, as the documentation, it will install the ARM version (for M1), but if you want to compile tools with Rosetta 2, you should have the Rosseta 2 version. Then you will have 2 brews, one for ARM and one for Rosseta 2, this shoud does the trick, cause now with the Rosseta 2 version you could install v8@3.15

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)"

Now I could use the ARM version as: brew and the Rosseta 2 version as: arch -x86_64 /usr/local/homebrew/bin/brew

This is explained here: https://stackoverflow.com/questions/64963370/error-cannot-install-in-homebrew-on-arm-processor-in-intel-default-prefix-usr

for the rest what I did was: gem install libv8 -v '3.16.14.19' -- --with-system-v8 gem install therubyracer -v '0.12.2' -- --with-v8-dir=/usr/local/Homebrew/opt/v8@3.15 (which is the path of v8 installed with Rosseta 2 brew)

For me this worked partially. I was able to bundle install after installig v8@3.15 for arch -x86_64 , but I got errors while trying to run rails s . In order to resolve errors encountered while running rails server, I had to install everything (brew, rvm, ruby, gems etc) in -x86_64 environment. Follow these instructions to launch terminal on mac in -x86_64 mode using rosetta 2 https://medium.com/swlh/run-x86-terminal-apps-like-homebrew-on-your-new-m1-mac-73bdc9b0f343

@besampson0
Copy link

besampson0 commented Oct 14, 2021

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!

@menehune23
Copy link

menehune23 commented Oct 20, 2021

These steps did not work for me on Catalina using the system Ruby; I used ruby-2.6.3 via RVM and things worked.

@jkingsman Thanks for noting this! Switching away from the system version of ruby was the only way I could get this working.

Note to readers, this is in reference to steps to do things like:

$ 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

@cpsteine
Copy link

cpsteine commented Dec 10, 2021

@KyleAsaff - I had this exact problem. It was maddening. You need to remove 'therubyracer' gem, and remove the 'less' gem and the 'less-rails' gem, assuming you're using one of them. They depend on TheRubyRacer to supply a JS runtime. You don't need it, as most systems have node now.

To preserve the less/scss functionality, use the 'sassc-rails' gem instead.

I called NodeJS out explicitly as my JS Runtime in the config/boot.rb file, but I also tried running the app without that line and it seems to fine without it.

I hope this helps.

@chrishough
Copy link

chrishough commented Jan 10, 2022

Has anyone got this working on OSX 12.1? These guides are not working correctly.

    current directory: /Users/christopherhough/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/sq_mini_racer-0.2.5.0.1.beta3/ext/mini_racer_extension
/Users/christopherhough/.rbenv/versions/2.5.7/bin/ruby -r ./siteconf20220110-69812-1jjiy7b.rb extconf.rb
  ERROR: found libv8-7.3.492.27.1, but no binary for x86_64-darwin-21
         try "gem install libv8 -v '7.3.492.27.1'" to attempt to build libv8 from source
*** 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
	--without-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/christopherhough/.rbenv/versions/2.5.7/bin/$(RUBY_BASE_NAME)
detected platform x86_64-darwin21 => x86_64-darwin-21
looking for libv8-7.3.492.27.1-x86_64-darwin-21.gemspec in installed gems
libv8-7.3.492.27.1-x86_64-darwin-21.gemspec not found in installed gems
looking for libv8-7.3.492.27.1-x86_64-darwin-21 in /Users/christopherhough/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/sq_mini_racer-0.2.5.0.1.beta3/ext/mini_racer_extension/vendor
libv8-7.3.492.27.1-x86_64-darwin-21 not found in /Users/christopherhough/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/sq_mini_racer-0.2.5.0.1.beta3/ext/mini_racer_extension/vendor

extconf failed, exit code 1

Gem files will remain installed in /Users/christopherhough/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/sq_mini_racer-0.2.5.0.1.beta3 for inspection.
Results logged to /Users/christopherhough/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-21/2.5.0/sq_mini_racer-0.2.5.0.1.beta3/gem_make.out

An error occurred while installing sq_mini_racer (0.2.5.0.1.beta3), and Bundler cannot continue.
Make sure that `gem install sq_mini_racer -v '0.2.5.0.1.beta3'` succeeds before bundling.```

@eveevans
Copy link

eveevans commented Jan 10, 2022

@paulhklam1122
Copy link

paulhklam1122 commented Jan 10, 2022

Has anyone gotten this to work for Ruby 3.1? I'm running into an issue where libv8 isn't able to be ran when upgrading to this ruby version.

@chrishough
Copy link

chrishough commented Jan 11, 2022

@eveevans so you could not get this to work in standard homebrew?

@eveevans
Copy link

eveevans commented Jan 11, 2022

@chrishough yes indeed, I'm using ASDF for Ruby (and Node)

@chrishough
Copy link

chrishough commented Jan 11, 2022

@eveevans from your command list I originally read that using arch linux, but I am new to asdf

@eveevans
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)

@chrishough
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

@redferret
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

https://stackoverflow.com/questions/66128681/ruby-build-failed-macos-11-2-using-ruby-build-20210119-mac-big-sur/66251271?noredirect=1#comment124076397_66251271

@barracuda156
Copy link

barracuda156 commented Jan 29, 2022

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

@BDanyil
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)
bundle

Worked on MacBook Pro 2020

@artoodeeto
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

@artoodeeto
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.

@channainfo
Copy link

channainfo commented Mar 8, 2022

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

@robbyrussell
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
      --with-mysql-config=/opt/homebrew/Cellar/mysql@5.7/5.7.36/bin/mysql_config
      --with-ldflags=-L/opt/homebrew/opt/openssl@1.1/lib 
      --with-cppflags=-I/opt/homebrew/opt/openssl@1.1/include

   bundle install  # installed mysql2 with native gems just fine  

@erik-escobedo
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 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

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)
bundle

worked for me, thanks

@vinay-kumar-g-c42
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

@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.

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