`gem install therubyracer` fails on Mac OS X Lion

2019-01-12 17:53发布

I would appreciate some help in getting gem install therubyracer to work. Here is the error:

$ gem install therubyracer
Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
    ERROR: Failed to build gem native extension.

        /Users/david/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for main() in -lobjc... yes
*** 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
    --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/david/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
    --with-objclib
    --without-objclib
extconf.rb:15:in `<main>': undefined method `include_path' for Libv8:Module (NoMethodError)

Here are some notable steps that I ran before the error. They worked fine:

$ gem install libv8
$ brew install v8

My environment is:

  • Mac OS X Lion 10.7.4
  • ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0] (via rvm)
  • V8 version 3.9.24 (via homebrew)

标签: ruby rubygems v8
11条回答
贼婆χ
2楼-- · 2019-01-12 18:19

Considering none if the above worked for me 100%, I thought I'd post what did (as part of a rails project):

gem uninstall libv8
bundle update therubyracer

This made sure I got the latest therubyracer, and also a more recent version of libV8, and seem to fix the multiple issues I was hitting, from missing libv8.a files, to undefined methods.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-12 18:23
gem uninstall libv8
brew install v8
gem install therubyracer
查看更多
淡お忘
4楼-- · 2019-01-12 18:23

I got a similar issue, but it was also complaining about not finding g++-4.2. I did have XCode command line tools installed, but it was looking for /usr/bin/g++-4.2, I had g++ (which was a symbolic link pointing to llvm-g++-4.2). Anyway, I just created a symbolic link to g++ and tried the bundle install again... it worked!

$ cd /usr/bin

$ sudo ln -s g++ g++-4.2

查看更多
等我变得足够好
5楼-- · 2019-01-12 18:25

At last I use therubyracer 0.11.0beta5 as a solution.

Using therubyracer (0.11.0beta5)

add following on Gemfile

gem 'therubyracer', '~> 0.11.0beta5'
group :libv8 do
  gem 'libv8', "~> 3.11.8"
end

then bundle install

Mac OSX 10.8 Moutain Lion

查看更多
Ridiculous、
6楼-- · 2019-01-12 18:30

For anyone encountering this issue on Mac OSX 10.8 Mountain Lion when attempting to upgrade their Gemfile with gem 'therubyracer', '0.11.0', just upgrading the system libv8 gem worked for me (no uninstallation of any other gem necessary):

$ gem update libv8
$ bundle install

Edit

If you use Travis-CI (or other CI tools located on other servers, I assume), you will need to explicitly add the libv8 gem to your Gemfile as well:

Gemfile

gem 'libv8', '3.11.8.3'

then bundle install as usual. Just note that libv8 can take a significant amount of time to install and I've noticed that it may end up being the cause of going over Travis CI's timeout limits, causing your build to fail. You can mitigate this slightly be not including development environment gems in your builds:

.travis.yml

# ...
bundler_args: --binstubs=./bundler_stubs --without development

Update

Yep, pretty much all my Travis builds timeout and fail because of this. If anyone knows a way to solve this problem (I would hope "downgrade therubyracer" is a last resort), please leave a comment!

Update 2

This may not work for all apps, but it seems that my Rails 3.2.9 apps didn't actually need therubyracer or libv8 after all. After removing those gems from my Gemfile, I confirmed that my specs passed, pushed again to Travis and it built successfully. So, I guess getting rid of those gems (if you're not sure you actually need them) is at least worth a try.

Update 3

Thanks to Paul Annesley for confirming that if you're on Mac OS X 10.8 Mountain Lion, you don't need therubyracer gem at all since the OS already comes bundled with Apple JavaScriptCore, its own Javascript runner. At the time of the original answer, I was on Snow Leopard and hence needed it.

查看更多
Summer. ? 凉城
7楼-- · 2019-01-12 18:31

But, why is this happening, you ask? And why does uninstalling libv8 and reinstalling therubyracer fix the problem?

The answer is at the bottom of the error message (from orig post). Ignore the stuff about

probably lack of necessary libraries and/or headers

This is an incorrect assumption by whoever wrote that error message. At the bottom, you see what Ruby has to say about it:

undefined method `include_path' for Libv8:Module

In my case, I was trying to install therubyracer-0.9.8 with bundle install, and for some reason, it was trying to use my copy of libv8-3.11.8.13, which had been installed at some point, probably as a dependency of some other gem.

I don't know why it was trying to use the newer version, because therubyracer.gemspec contains s.add_dependency "libv8", "~> 3.3.10". And my Gemfile.lock says to use libv8 (3.3.10.2). But alas, that is indeed what was happening.

And it's true that Libv8:Module does not have the method include_path in libv8-3.11.8.13, but it does in libv8-3.3.10.2

So that is why uninstalling all of your versions of libv8 and then re-installing therubyracer works. Because all the versions of libv8 that do not have the method include_path are removed completely, and the libv8 that does have the method include path is reinstalled when you reinstall of therubyracer.

查看更多
登录 后发表回答