Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing libv8 gem on OS X 10.9+

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)


You can configure bundler instead of having to know each version. @3.15 could be replaced with other versions.

$ brew install [email protected]
$ bundle config build.libv8 --with-system-v8
$ bundle config build.therubyracer --with-v8-dir=$(brew --prefix [email protected])
$ bundle install

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.


My issue is since therubyracer, when update to macOS 10.15 and ruby-2.6.5

And the following works for me:

brew install [email protected]

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

gem install therubyracer -- --with-v8-dir=/usr/local/opt/[email protected]

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