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

This comment has been minimized.

Copy link

Alphabetus commented Jun 18, 2019

Still works on 2019!
ruby 2.2.5

Thanks

@fernandoaleman

This comment has been minimized.

Copy link
Owner Author

fernandoaleman commented Jun 18, 2019

@Alphabetus You're welcome. Glad it helped.

@ZhdanovP

This comment has been minimized.

Copy link

ZhdanovP commented Jul 16, 2019

Hello, @Alphabetus , I am getting the following error during the
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315
Do you have guess why it can by?

current directory: /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/ext/libv8 /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20190716-50046-104ausw.rb extconf.rb --with-v8-dir=/usr/local/opt/v8-315 creating Makefile Applying /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/patches/disable-building-tests.patch Applying /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/patches/disable-werror-on-osx.patch Applying /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/patches/disable-xcode-debugging.patch Applying /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/patches/do-not-imply-vfp3-and-armv7.patch Applying /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/patches/do-not-use-MAP_NORESERVE-on-freebsd.patch Applying /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/patches/do-not-use-vfp2.patch Applying /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/patches/fPIC-for-static.patch Compiling v8 for x64 Using python 2.7.15 Using compiler: c++ (Apple LLVM version 10.0.1) Unable to find a compiler officially supported by v8. It is recommended to use GCC v4.4 or higher Beginning compilation. This will take some time. Building v8 with env CXX=c++ LINK=c++ /usr/bin/make x64.release ARFLAGS.target=crs werror=no GYP_GENERATORS=make \ build/gyp/gyp --generator-output="out" build/all.gyp \ -Ibuild/standalone.gypi --depth=. \ -Dv8_target_arch=x64 \ -S.x64 -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 -Dwerror='' CXX(target) /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found] In file included from ../src/allocation.cc:33: ../src/utils.h:33:10: fatal error: 'climits' file not found #include <climits> ^~~~~~~~~ 1 warning and 1 error generated. make[1]: *** [/Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o] Error 1 make: *** [x64.release] Error 2 /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:36:in block in verify_installation!': libv8 did not install properly, expected binary v8 archive '/Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a'to exist, but it was not found (Libv8::Location::Vendor::ArchiveNotFound)
from /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:35:in each' from /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:35:in verify_installation!'
from /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:26:in install!' from extconf.rb:7:in

'

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/libv8-3.16.14.19 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/libv8-3.16.14.19/gem_make.out`

@gurdiga

This comment has been minimized.

Copy link

gurdiga commented Aug 8, 2019

The therubyracer installation didn’t for me, I still got this:

checking for v8.h... no

Here is what worked for me:

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

Good luck! 🙂

@fernandoaleman

This comment has been minimized.

Copy link
Owner Author

fernandoaleman commented Aug 8, 2019

@gurdiga Hey glad that worked for you. That code will definitely be helpful for others using therubyracer. Thanks for sharing! 👍

I actually stopped using therubyracer and instead started installing the nodejs package for Javascript. So far, it's worked well. 😊

@simshanith

This comment has been minimized.

Copy link

simshanith commented Sep 3, 2019

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 ^

@zazk

This comment has been minimized.

Copy link

zazk commented Sep 3, 2019

Thanks @fernandoaleman, @gurdiga! You guys rocks!

@monteirobrena

This comment has been minimized.

Copy link

monteirobrena commented Sep 12, 2019

Thank you!

@tvcam

This comment has been minimized.

Copy link

tvcam commented Oct 3, 2019

Awesome.

@zismailov

This comment has been minimized.

Copy link

zismailov commented Oct 21, 2019

Thank you! 2019

@kokorolx

This comment has been minimized.

Copy link

kokorolx commented Nov 1, 2019

It still working when I use rails 4 and ruby 2.1.1
Thank you!

@nzajt

This comment has been minimized.

Copy link

nzajt commented Nov 6, 2019

If you need to do this with macOS 10.15 and ruby 2.3 here it is

brew install v8@3.15
gem install libv8 -v 'YOUR_VERSION' -- --with-system-v8
gem install therubyracer -v 'YOUR_VERSION' -- --with-v8-dir=/usr/local/opt/v8@3.15
bundle install
@gordey4doronin

This comment has been minimized.

Copy link

gordey4doronin commented Nov 12, 2019

Confirmed! Still works in Catalina, with small changes in version path, and without additional brew tap. Thanks! 👍

@kennethkalmer

This comment has been minimized.

Copy link

kennethkalmer commented Nov 12, 2019

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

This comment has been minimized.

Copy link

TomHoenderdos commented Nov 13, 2019

@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

@kenn

This comment has been minimized.

Copy link

kenn commented Nov 13, 2019

Please don't mention my username :) Thanks!

@paluchas

This comment has been minimized.

Copy link

paluchas commented Nov 29, 2019

Bundler version works perfectly on Catalina + Ruby managed by chruby. Thanks!

Note, that bundle config will update global bundler config file .e.g

$ cat ~/.bundle/config                                                          ✹ ✭
---
BUNDLE_BUILD__LIBV8: "--with-system-v8"
BUNDLE_BUILD__THERUBYRACER: "--with-v8-dir=/usr/local/opt/v8@3.15"
@bpdarlyn

This comment has been minimized.

Copy link

bpdarlyn commented Dec 5, 2019

I have Catalina + Ruby 2.6.2 and It doesn't work, could you please tell me the error ?

Fetching libv8 3.16.14.19
Installing libv8 3.16.14.19 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/bpdarlyn/.rvm/gems/ruby-2.6.2/gems/libv8-3.16.14.19/ext/libv8
/Users/bpdarlyn/.rvm/rubies/ruby-2.6.2/bin/ruby -I /Users/bpdarlyn/.rvm/rubies/ruby-2.6.2/lib/ruby/site_ruby/2.6.0 -r
./siteconf20191204-32835-fl2n5d.rb extconf.rb --with-cxx\=/usr/local/bin/g\+\+-4.2
creating Makefile
/Users/bpdarlyn/.rvm/gems/ruby-2.6.2/gems/libv8-3.16.14.19/ext/libv8/builder.rb:56:in `block in build_libv8!': No compilers
available (RuntimeError)
	from /Users/bpdarlyn/.rvm/gems/ruby-2.6.2/gems/libv8-3.16.14.19/ext/libv8/builder.rb:54:in `chdir'
	from /Users/bpdarlyn/.rvm/gems/ruby-2.6.2/gems/libv8-3.16.14.19/ext/libv8/builder.rb:54:in `build_libv8!'
	from /Users/bpdarlyn/.rvm/gems/ruby-2.6.2/gems/libv8-3.16.14.19/ext/libv8/location.rb:24:in `install!'
	from extconf.rb:7:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/bpdarlyn/.rvm/gems/ruby-2.6.2/gems/libv8-3.16.14.19 for inspection.
Results logged to /Users/bpdarlyn/.rvm/gems/ruby-2.6.2/extensions/x86_64-darwin-19/2.6.0/libv8-3.16.14.19/gem_make.out

An error occurred while installing libv8 (3.16.14.19), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.16.14.19' --source 'https://rubygems.org/'` succeeds before bundling.
cat ~/.bundle/config
---
BUNDLE_BUILD__LIBV8: "--with-system-v8"
BUNDLE_BUILD__THERUBYRACER: "--with-v8-dir=/usr/local/opt/v8@3.15"
@bjoseru

This comment has been minimized.

Copy link

bjoseru commented Dec 12, 2019

I ran into the same problems (on Catalina) and there seem to have been some changes to homebrew. After a lot of trial and error the following worked for me:

  1. Install homebrew into my home directory (I am using MacPorts otherwise, but their v8 is currently broken) under ~/homebrew. You can choose a different folder of course, or choose a global installation instead. In that case all the paths below need to be updated.
 cd
 mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
  1. As I am not planning to use homebrew in the future, I don't add it to PATH, just make it available short term like so:
alias brew="~/homebrew/bin/brew"
  1. Update homebrew's knowledge about older versions. This replaces the brew tap homebrew/versions step.
git -C "$(brew --repo homebrew/core)" fetch --unshallow
  1. Proceed to install this old version of v8 that rubyracer wants:
brew install v8@3.15

Now check where this actually went to, for me it is under ~/homebrew/opt/v8@3.15. This locations should contain include/v8.h.

  1. Find an appropriate gem version of libv8 and install it.
# check for name of v8 install directory, then
gem list libv8 --remote --all # => 3.16.14.19 is seems like a good candidate
gem install libv8 -v 3.16.14.19 -- --with-system-v8

In the second command I also had --with-v8-dir=~/homebrew/opt/v8@3.15 but I don't think it did anything, so I removed it here.

  1. Install rubyracer like so. Importantly, do not use a relative path, use an absolute path for the installation directory of v8:
gem install therubyracer -- --with-v8-dir=/Users/<your username here>/homebrew/opt/v8@3.15 # here the absolute path is VITAL

And that is it. Good luck!

@bjoseru

This comment has been minimized.

Copy link

bjoseru commented Dec 12, 2019

PS: In case you previously installed other (newer, but non-working) versions of libv8, likely by using the --with-system-v8 option, and likely so that they don't actually work, then remove them with gem uninstall before you follow the instructions above.

@wlchn

This comment has been minimized.

Copy link

wlchn commented Dec 13, 2019

@bjoseru thanks, wroks for macOS 10.15 and ruby-2.6.5

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

This comment has been minimized.

Copy link

abournier commented Dec 15, 2019

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

Works perfectly for Catalina and Ruby 2.6.3. (after having testings many many things !) Thanks !

@ghost

This comment has been minimized.

Copy link

ghost commented Dec 17, 2019

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

@kennethkalmer you are the MAN!!!

@iTamilan

This comment has been minimized.

Copy link

iTamilan commented Dec 18, 2019

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

I tried every combination but this works perfectly. Thanks! @kennethkalmer

@kylebradshaw

This comment has been minimized.

Copy link

kylebradshaw commented Dec 19, 2019

^^^^^^^^^ thanks @iTamilan

@renny-ren

This comment has been minimized.

Copy link

renny-ren commented Dec 31, 2019

thanks @iTamilan

@wagnerpereira

This comment has been minimized.

Copy link

wagnerpereira commented Jan 3, 2020

If you need to do this with macOS 10.15 and ruby 2.3 here it is

brew install v8@3.15
gem install libv8 -v 'YOUR_VERSION' -- --with-system-v8
gem install therubyracer -v 'YOUR_VERSION' -- --with-v8-dir=/usr/local/opt/v8@3.15
bundle install

Confirmed Catalina 10.15.2!

@paulhklam1122

This comment has been minimized.

Copy link

paulhklam1122 commented Jan 6, 2020

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

This comment has been minimized.

Copy link

ssjod commented Jan 6, 2020

Using homebrew's directory of v8 for --with-v8-dir=/usr/local/Cellar/v8@3.15/3.15.11.18_1, instead of /usr/local/opt/v8-315, is what worked for me, in coding addicted's answer.

This is visible in the Summary of the brew install command, brew install v8-315.

@KiranJosh

This comment has been minimized.

Copy link

KiranJosh commented Jan 8, 2020

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

The therubyracer installation didn’t for me, I still got this:

checking for v8.h... no

Here is what worked for me:

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

Good luck! 🙂

It worked for me, thanks

@jkingsman

This comment has been minimized.

Copy link

jkingsman commented Jan 10, 2020

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

@SeemabMehmood

This comment has been minimized.

Copy link

SeemabMehmood commented Jan 14, 2020

$ bundle install

Awsome! Worked !

@barneyhsiao

This comment has been minimized.

Copy link

barneyhsiao commented Jan 17, 2020

If you need to do this with macOS 10.15 and ruby 2.3 here it is

brew install v8@3.15
gem install libv8 -v 'YOUR_VERSION' -- --with-system-v8
gem install therubyracer -v 'YOUR_VERSION' -- --with-v8-dir=/usr/local/opt/v8@3.15
bundle install

Worked beautifully for me. Thanks!

  • macOS Catalina 10.15.1
  • therubyracer (0.12.3)
  • libv8 (3.16.14.19 x86_64-linux)
  • rails (4.1.15)
  • bundler (1.16.2)
@thiagodsalles

This comment has been minimized.

Copy link

thiagodsalles commented Jan 24, 2020

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

Perfect!

@karuppasamy

This comment has been minimized.

Copy link

karuppasamy commented Jan 27, 2020

@thiagodsalles

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
Perfect!

Worked perfectly.

  • bundler (1.17.2)
  • rails (4.2.11.1)
  • libv8 (3.15-3.15.11.18_1)
  • therubyracker (0.12.3)
  • macOS Catalina (10.15.2)
@AstmDesign

This comment has been minimized.

Copy link

AstmDesign commented Feb 14, 2020

Hi @gurdiga, your solving is working well with me

My Mac OS is Mojave 10.14.4

Rails 5.1.1

Ruby 2.5.3

Was got the error checking for v8.h... no

and fixed it by using

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

thanks my bro

@aleks-rope

This comment has been minimized.

Copy link

aleks-rope commented Feb 19, 2020

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

Still works in 2020!

@arvinwiyono

This comment has been minimized.

Copy link

arvinwiyono commented Feb 20, 2020

Still works in macOS Catalina in 2020!

brew install v8-315
gem install libv8 -v '3.16.14.19' -- --with-system-v8
@sachinswagh

This comment has been minimized.

Copy link

sachinswagh commented Feb 20, 2020

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

This worked for me . :)

@gyanpgupta

This comment has been minimized.

Copy link

gyanpgupta commented Feb 25, 2020

I did on Catalina...it is working 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

@ruvaleev

This comment has been minimized.

Copy link

ruvaleev commented Mar 16, 2020

The therubyracer installation didn’t for me, I still got this:

checking for v8.h... no

Here is what worked for me:

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

Good luck! 🙂

Only this worked for me!

@chuyihuang

This comment has been minimized.

Copy link

chuyihuang commented Mar 21, 2020

thank god it's still working March, 2020

@zhaoawd

This comment has been minimized.

Copy link

zhaoawd commented Mar 21, 2020

I did on Catalina...it is working 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
Only this worked for me on Catalina .

@jonathantsang

This comment has been minimized.

Copy link

jonathantsang commented Mar 22, 2020

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

this worked ty.

@CatPerry

This comment has been minimized.

Copy link

CatPerry commented Mar 30, 2020

$ 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

@kennethkalmer solution worked for me as well.

@jedidrew42

This comment has been minimized.

Copy link

jedidrew42 commented Mar 30, 2020

I am getting this error after following the Less installation on Mac running Catalina.

[WARNING] Please install gem 'therubyracer' to use Less.
Traceback (most recent call last):
15: from /usr/local/bin/lessc:23:in <main>' 14: from /usr/local/bin/lessc:23:in load'
13: from /Library/Ruby/Gems/2.6.0/gems/less-2.6.0/bin/lessc:3:in <top (required)>' 12: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require'
11: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' 10: from /Library/Ruby/Gems/2.6.0/gems/less-2.6.0/lib/less.rb:9:in <top (required)>'
9: from /Library/Ruby/Gems/2.6.0/gems/less-2.6.0/lib/less.rb:14:in <module:Less>' 8: from /Library/Ruby/Gems/2.6.0/gems/less-2.6.0/lib/less.rb:14:in new'
7: from /Library/Ruby/Gems/2.6.0/gems/less-2.6.0/lib/less/loader.rb:13:in initialize' 6: from /Library/Ruby/Gems/2.6.0/gems/less-2.6.0/lib/less/java_script.rb:17:in context_wrapper'
5: from /Library/Ruby/Gems/2.6.0/gems/less-2.6.0/lib/less/java_script.rb:9:in default_context_wrapper' 4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require'
3: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' 2: from /Library/Ruby/Gems/2.6.0/gems/less-2.6.0/lib/less/java_script/v8_context.rb:2:in <top (required)>'
1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- v8 (LoadError)

@jedidrew42

This comment has been minimized.

Copy link

jedidrew42 commented Mar 30, 2020

@CatPerry I tried to install using your methods but I am getting this message Could not locate Gemfile

@CatPerry

This comment has been minimized.

Copy link

CatPerry commented Mar 30, 2020

@CatPerry I tried to install using your methods but I am getting this message Could not locate Gemfile

@jedidrew42 try gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8@3.15 then try these steps. I wasnt installing or using Less, so this error isnt one that I ran into. Not sure beyond this^

@gamrom

This comment has been minimized.

Copy link

gamrom commented Apr 1, 2020

The therubyracer installation didn’t for me, I still got this:

checking for v8.h... no

Here is what worked for me:

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

Good luck! 🙂

thankyou it really works for me!

@gulymaestro

This comment has been minimized.

Copy link

gulymaestro commented Apr 3, 2020

Here is what worked for me:

gem install libv8 -v 'version' -- --with-system-v8
rvm autolibs disable
brew unlink v8
brew link v8@3.15 --force
gem install therubyracer -v 'version'
brew unlink v8@3.15
brew link v8
rvm autolibs enabled

Cheers!

@tomchapin

This comment has been minimized.

Copy link

tomchapin commented Apr 3, 2020

None of this helped me... no matter what I did, my gem install of therubyracer kept complaining with this error:

Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Beginning compilation. This will take some time.
Building v8 with env CXX=clang++ LINK=clang++  /usr/local/bin/gmake x64.release ARFLAGS.target=crs werror=no
GYP_GENERATORS=make \
build/gyp/gyp --generator-output="out" build/all.gyp \
              -Ibuild/standalone.gypi --depth=. \
              -Dv8_target_arch=x64 \
              -S.x64 -Dmac_deployment_target=10.15 -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 -Dwerror=''
  File "build/gyp/gyp", line 12
    except ImportError, e:
                      ^
SyntaxError: invalid syntax
gmake: *** [Makefile:268: out/Makefile.x64] Error 1

What ultimately helped me was this other forum I stumbled upon at https://www.bountysource.com/issues/82833405-libv8-fails-to-build-on-catalina-10-15

The final solution that worked for me:

I had to add these lines to my .zshrc file:

export CXX=clang++
export GYPFLAGS=-Dmac_deployment_target=10.15

Then I had to run these commands:

source ~/.zshrc
brew tap homebrew/homebrew-core
brew install v8@3.15
gem uninstall therubyracer
gem uninstall libv8
gem install libv8 -v '3.16.14.19' -- --with-system-v8
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15
bundle install

I hope someone else finds this useful!

@HuzaifaSaifuddin

This comment has been minimized.

Copy link

HuzaifaSaifuddin commented Apr 5, 2020

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

This worked for me MacOS 10.15, Ruby 2.4.2. Thanks.

@amolpujari

This comment has been minimized.

Copy link

amolpujari commented Apr 8, 2020

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

@kennethkalmer thanks, worked for me too

@vvleon314

This comment has been minimized.

Copy link

vvleon314 commented Apr 22, 2020

worked in 2020, April.
Thanks guys

@zainalmustofa

This comment has been minimized.

Copy link

zainalmustofa commented Apr 30, 2020

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

it work.. Thank you!!

@chaitanyamanyam

This comment has been minimized.

Copy link

chaitanyamanyam commented May 15, 2020

I did on Catalina...it is working 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

This worked. Thanks

@gizipp

This comment has been minimized.

Copy link

gizipp commented May 18, 2020

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

Works perfectly. Thanks.

@aleks-rdea

This comment has been minimized.

Copy link

aleks-rdea commented May 23, 2020

Cheers!!

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

This comment has been minimized.

Copy link

nachoal commented May 26, 2020

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

This one worked on Catalina 10.15.4

@klion26

This comment has been minimized.

Copy link

klion26 commented May 27, 2020

tried all the above did not work for me(10.15.4 (19E287)),
worked for me after upgrade ruby to 2.7.1p83 by using brew install ruby and the previous solutions.

@jirihradil

This comment has been minimized.

Copy link

jirihradil commented May 28, 2020

This still works on Catalina 10.15.5 (ruby 2.4.4):

brew install v8@3.15
gem install libv8 -v '3.16.14.19' -- --with-system-v8
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15

Thanks!

@josephtyler

This comment has been minimized.

Copy link

josephtyler commented Jun 5, 2020

@bjoseru thanks, wroks for macOS 10.15 and ruby-2.6.5

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 appears to be the correct incantation, thank you.

@stkzk3110

This comment has been minimized.

Copy link

stkzk3110 commented Jun 6, 2020

This still works on Catalina 10.15.4 (ruby 2.3.0):

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

@kennethkalmer thanks!

@tomrossi7

This comment has been minimized.

Copy link

tomrossi7 commented Jun 17, 2020

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 today on OSX 10.15.5 and Ruby 2.6.4

@amravazzi

This comment has been minimized.

Copy link

amravazzi commented Jun 17, 2020

This still works on Catalina 10.15.5 (ruby 2.4.4):

brew install v8@3.15
gem install libv8 -v '3.16.14.19' -- --with-system-v8
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15

Thanks!

Worked as June 2020, macOS Catalina!

@mantrala

This comment has been minimized.

Copy link

mantrala commented Jun 22, 2020

This is what worked for me on Catalina

brew install v8@3.15
bundle config --local build.libv8 --with-system-v8
bundle config --local build.therubyracer --with-v8-dir=/usr/local/opt/v8@3.15
bundle install
@gyandeeps

This comment has been minimized.

Copy link

gyandeeps commented Jun 22, 2020

It fails for me as i have tried all type of suggestions in this post.
Its able to find v8.h file but during its parsing has issues.

I get the same error as

Building native extensions with: '--with-v8-dir=/usr/local/opt/v8@3.15'
This could take a while...
ERROR:  Error installing therubyracer:
	ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/therubyracer-0.12.3/ext/v8
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200622-88683-125x6b4.rb extconf.rb --with-v8-dir\=/usr/local/opt/v8@3.15
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
	--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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/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
/Library/Ruby/Gems/2.6.0/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 /Library/Ruby/Gems/2.6.0/gems/libv8-3.16.14.19/lib/libv8.rb:7:in `configure_makefile'
	from extconf.rb:32:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/therubyracer-0.12.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/therubyracer-0.12.3 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/therubyracer-0.12.3/gem_make.out

Here is the error log:

nd_header: checking for v8.h... -------------------- no

"xcrun clang -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -I/usr/local/opt/v8@3.15/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -Wall -g -rdynamic  -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS  -arch x86_64  -c conftest.c"
clang: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument]
In file included from conftest.c:3:
/usr/local/opt/v8@3.15/include/v8.h:98:1: error: unknown type name 'namespace'
namespace v8 {
^
/usr/local/opt/v8@3.15/include/v8.h:98:13: error: expected ';' after top level declarator
namespace v8 {
            ^
            ;
2 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <v8.h>
/* end */

More info:

gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
@catherynl

This comment has been minimized.

Copy link

catherynl commented Jun 23, 2020

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

No idea what's happening but this totally worked for me (June 2020)!

@adilw3nomad

This comment has been minimized.

Copy link

adilw3nomad commented Jun 26, 2020

Yep this worked for me...

@rrobiso

This comment has been minimized.

Copy link

rrobiso commented Jun 26, 2020

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

No idea what's happening but this totally worked for me (June 2020)!

Absolutely! This worked for me too! June 2020

@weliame

This comment has been minimized.

Copy link

weliame commented Jun 30, 2020

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

This is awesome. It still works for me! Thanks so much.

@ajmaurya99

This comment has been minimized.

Copy link

ajmaurya99 commented Jul 2, 2020

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

Working for me for Catalina - July 2020

@dp21g

This comment has been minimized.

Copy link

dp21g commented Jul 9, 2020

It fails for me as i have tried all type of suggestions in this post.
Its able to find v8.h file but during its parsing has issues.

I get the same error as

Building native extensions with: '--with-v8-dir=/usr/local/opt/v8@3.15'
This could take a while...
ERROR:  Error installing therubyracer:
	ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/therubyracer-0.12.3/ext/v8
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200622-88683-125x6b4.rb extconf.rb --with-v8-dir\=/usr/local/opt/v8@3.15
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
	--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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/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
/Library/Ruby/Gems/2.6.0/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 /Library/Ruby/Gems/2.6.0/gems/libv8-3.16.14.19/lib/libv8.rb:7:in `configure_makefile'
	from extconf.rb:32:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/therubyracer-0.12.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/therubyracer-0.12.3 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/therubyracer-0.12.3/gem_make.out

Here is the error log:

nd_header: checking for v8.h... -------------------- no

"xcrun clang -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -I/usr/local/opt/v8@3.15/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -Wall -g -rdynamic  -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS  -arch x86_64  -c conftest.c"
clang: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument]
In file included from conftest.c:3:
/usr/local/opt/v8@3.15/include/v8.h:98:1: error: unknown type name 'namespace'
namespace v8 {
^
/usr/local/opt/v8@3.15/include/v8.h:98:13: error: expected ';' after top level declarator
namespace v8 {
            ^
            ;
2 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <v8.h>
/* end */

More info:

gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

mine was doing the same with some of the Cerner repos. My issue was my gem env was set to the system default location and I had recently installed rvm but not refreshed my terminal to pick up rvm as default ruby management of gems. Closing and opening terminal and testing gem env changed to correct locations seems to have done the trick.

@LucasKuhn

This comment has been minimized.

Copy link

LucasKuhn commented Jul 16, 2020

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 here as well. Thank you!

@ren6

This comment has been minimized.

Copy link

ren6 commented Jul 17, 2020

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 here as well. Thank you!

Worked for me too.

@mirzalazuardi

This comment has been minimized.

Copy link

mirzalazuardi commented Jul 29, 2020

Work like a charm. Great solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.