如何在 mac 上安装 therubyracer? “gem install therubyracer -v”不工作

Posted

技术标签:

【中文标题】如何在 mac 上安装 therubyracer? “gem install therubyracer -v”不工作【英文标题】:How to install therubyracer on mac? "gem install therubyracer -v " not working 【发布时间】:2020-10-06 07:57:14 【问题描述】:

我一直在尝试安装 therubyracer,并尝试了我在 *** 上能找到的几乎所有方法,但它似乎仍然给我同样的错误。我也是 ruby​​ on rails 的新手,所以我无法准确浏览错误消息。以下是错误信息:

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

【问题讨论】:

【参考方案1】:

如错误消息所述,您使用的是 Clang,但您安装的过时版本的 libv8 仅支持 GCC。

请注意,therubyracer 的最新版本是 2017 年 1 月(看起来自 2013 年初以来没有任何开发),它使用的 libv8 版本也是如此(当然,附带的 V8 版本使用该版本的 libv8)。它建议从 2012 年开始使用 GCC 4.4。

我怀疑你会得到对这样一个旧版本的 libv8、V8 或 GCC 的任何支持。另外请注意,当时还没有 Ruby 2.7,2017 年初的当前 Ruby 版本应该是 2.4,2013 年初是 2.0。

【讨论】:

所以我可以让 therubyracer 工作的唯一方法是安装 GCC?并且还使用 Ruby v 2.4 及更低版本? 我也有类似的问题。我相信这是 Ruby 的依赖,但 therubyracer。最新的是 therubyracer (0.12.3),它依赖于 libv8 (~> 3.16.14.15),并且 libv8 不能在最新的 clang 上编译。这就是原因。解决的唯一方法似乎是替换 ruby​​racer 或更新它以使用更新的 libv8。【参考方案2】:

您可能没有v8的系统版本,您可以执行以下操作:

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

这假设您在 Mac 上具有典型的开发人员设置 - 安装了命令行工具的最新 Xcode。

原答案:https://github.com/rubyjs/libv8/issues/282#issuecomment-568538097

【讨论】:

以上是关于如何在 mac 上安装 therubyracer? “gem install therubyracer -v”不工作的主要内容,如果未能解决你的问题,请参考以下文章

therubyracer gem 安装错误 - mac 10.9

therubyracer 安装错误

如何使用预安装的 libv8 gem 和预编译的 v8 依赖项在 aarch64 上安装 therubyracer?

使用 less (2.2.1) 会引发需要 therubyracer 的错误(无法在 Windows 上安装 therubyracer)

无法在 centos 上安装 therubyracer(V8 和 GCC 出错)

无法在 Mountain Lion 上安装 therubyracer -v '0.10.0'