ruby-on-railsrubyrubygemstherubyracer

How to install therubyracer on mac? "gem install therubyracer -v " not working


I have been trying to install therubyracer and tried almost all that i could find on stackoverflow but it still seems to give me the same error. I am also new to ruby on rails so I cant exactly navigate through the error message. Below is the error message:

ERROR:  Error installing therubyracer:
        ERROR: Failed to build gem native extension.

    current directory: /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/ext/libv8
/Users/zoepa/.rvm/rubies/ruby-2.7.0/bin/ruby -I /Users/zoepa/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0 -r ./siteconf20200616-2984-xp1oct.rb extconf.rb --with-v8-dir\=/usr/local/opt/v8@3.15
creating Makefile
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/disable-building-tests.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/disable-werror-on-osx.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/disable-xcode-debugging.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/do-not-imply-vfp3-and-armv7.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/do-not-use-MAP_NORESERVE-on-freebsd.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/do-not-use-vfp2.patch
Applying /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/patches/fPIC-for-static.patch
Compiling v8 for x64
Using python 2.7.16
Using compiler: c++ (clang version 11.0.0)
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) /Users/zoepa/.rvm/gems/ruby-2.7.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]: *** [/Users/zoepa/.rvm/gems/ruby-2.7.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
/Users/zoepa/.rvm/gems/ruby-2.7.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 '/Users/zoepa/.rvm/gems/ruby-2.7.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 /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:35:in `each'
        from /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:35:in `verify_installation!'
        from /Users/zoepa/.rvm/gems/ruby-2.7.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:26:in `install!'
        from extconf.rb:7:in `<main>'

extconf failed, exit code 1

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


Solution

  • As the error message says, you are using Clang, but the outdated version of libv8 you are installing only supports GCC.

    Note that the latest version of therubyracer is from January 2017 (and it looks like there hasn't been any development since early 2013), and so is the version of libv8 it uses (and naturally, the version of V8 that ships with that version of libv8). It suggests using GCC 4.4 from 2012.

    I doubt you will get any support for such an old version of libv8, V8, or GCC. Also, please note that Ruby 2.7 didn't exist back then, the current version of Ruby in early 2017 would have been 2.4, in early 2013 2.0.