Installing libv8 gem on OS X 10.9+

自古美人都是妖i 提交于 2019-11-27 09:58:08
Gaurav Agarwal

This is due to the fact that OS X 10.9+ is using version 4.8 of GCC. This is not supported officially in older versions of libv8 as mentioned in the pull request (https://github.com/cowboyd/libv8/pull/95). Please try bumping up the version of libv8 in your Gemfile (or) a bundle update should suffice. Hope this helps.

From the libv8 README

Bring your own V8

Because libv8 is the interface for the V8 engine used by therubyracer, you may need to use libv8, even if you have V8 installed already. If you wish to use your own V8 installation, rather than have it built for you, use the --with-system-v8 option.

Using RubyGems:

gem install libv8 [-v YOUR_VERSION] -- --with-system-v8

Using Bundler (in your Gemfile):

bundle config build.libv8 --with-system-v8

Please note that if you intend to run your own V8, you must install both V8 and its headers (found in libv8-dev for Debian distros).

Bring your own compiler

You can specify a compiler of your choice by either setting the CXX environment variable before compilation, or by adding the --with-cxx= option to the bundle configuration:

bundle config build.libv8 --with-cxx=clang++

Edit:

If this issue is brought on by therubyracer, try the following as suggested by rider_on_rails here:

gem uninstall libv8

gem install therubyracer -v YOUR_RUBY_RACER_VERSION

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

You can actually install that version on Mavericks:

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

I can confirm this works with rbenv and ruby 1.9.3p448

El Capitan Solution for me:

$ brew install v8
$ gem install libv8 -v REQUIRED_LIBV8_VERSION -- --with-system-v8

Where REQUIRED_LIBV8_VERSION for me was 3.16.14.7, but you need to check which is the one you need in your bundle (this was the one for rails 4.2.5)

You may also need to run the commands above as the superuser (if your gems and system libraries are global)

When I tried the accepted answer, libv8 would install successfully with gem install libv8, but bundle install would fail on libv8. I think that bundle install was trying to install a different version of libv8. I was able to find a solution that worked for me.

I needed libv8 because therubyracer depends on it. To get it to install, I noted the version that was failing to install in the gem_make.out log for therubyracer. (The path for the gem_make.out log will be in the failure message.) In my case it was 3.16.14.7. (This version will probably change over time, in case you're reading this three years from now.) Then I did this:

gem install libv8 -v 3.16.14.7 -- --with-v8-lib <-- note different flag from accepted answer

which allowed this to work:

gem install therubyracer

which allowed me to complete my bundle install.

This worked for me on OSX Yosemite.

https://github.com/cowboyd/therubyracer/issues/339

jasonlynes's solution found on that link made the trick for me. anything else didn't work.

brew install homebrew/versions/v8-315
brew link --overwrite v8-315 --force
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -v '0.12.2' -- --with-system-v8
damianmr

Try with what I summarized in this question: "gem install therubyracer -v '0.10.2'" on osx mavericks not installing

It worked for me (OS X Mavericks)

I had this same problem when I upgraded from OSX Mountain Lion to OSX Mavericks. The accepted answer worked for libv8, but not when I went to bundle install therubyracer gem.

Upgrading from ruby-1.8.7-p354 to ruby-1.8.7-375 did the trick for me. libv8 (3.16.14.3-x86_64-darwin-13) and the therubyracer (0.12.0) gems installed without problem.

assuming you use rbenv:

rbenv versions
  system
  * 1.8.7-p354
  2.0.0-rc2

rbenv uninstall 1.8.7-p354
rbenv install 1.8.7-p375

rbenv versions
  system
  * 1.8.7-p375
  2.0.0-rc2

bundle install
Tilo

This worked fine for me:

Try installing this pre-compiled gem:

https://dl.dropboxusercontent.com/u/7919548/gems/libv8/libv8-3.11.8.17-x86_64-darwin-13.gem (sha1:5ce07aaf4085fff5a5e10fe018fd6b22021bef3b)

Or if you prefer to build your own:

  git clone https://github.com/cowboyd/libv8.git
  cd libv8
  git checkout 3.11
  bundle install
  bundle exec rake clean build binary
  gem install pkg/libv8-3.11.8.17-x86_64-darwin-13.gem

Source: https://github.com/cowboyd/libv8/issues/107

Thanks to Felix Bünemann for the fix!

XtraSimplicity

I tried a number of solutions outlined in previous answers, but found that running bundle (to install other, missing gems) would attempt to re-compile libv8 (despite having already installed it successfully using --with-system-v8) and thus suffer from the same issue.

Eventually, I found that removing the libv8 gem, fetching the gem file from rubygems, and then manually installing the .gem file with the --with-system-v8 flag worked for me.

i.e.

gem uninstall libv8
gem fetch libv8 -v LIBV8_VERSION
gem install libv8-LIBV_VERSION.gem -- --with-system-v8
bundle

Thanks to Gaurav Agarwal's answer for leading me down the right path!

You can try manually compiling and installing the gem via the method mentioned on the libv8 github site.

In MAC-Yosemite with RVM environment and ruby-2.1.1 version

gem install libv8 -v 3.16.14.3 -- --with-v8-lib gem install therubyracer

It works with the help of above command, can confirm this.

What really worked for me was upgrading ruby to 2.2.0, removing Gemfile.lock and bundling over again.

Worked like a charm!

This is what worked for me.

replace 3.16.14.7 with your version.

bundle install
gem install libv8 -v '3.16.14.7' -- --with-system-v8

bundle install
gem uninstall libv8 -v '3.16.14.7' -- --with-system-v8

brew install homebrew/dupes/apple-gcc42

export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2

bundle install

I have faced a similar problem on El Cap. Here's what I did.

brew tap homebrew/dupes
brew install apple-gcc42

And then,

export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2

Finally,

brew uninstall v8
gem install libv8 -v 3.11.8.17 -- --with-system-v8

I was using a beta version of Xcode for another project and had forgotten. Switch back with xcode-select. Something like:

sudo xcode-select --switch /Applications/Xcode.app/

Remove from Gemfile:

gem 'therubyracer', :platforms => :ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!