101

I don't manage to install therubyracer gem on Yosemite 10.10.

Here is the log:

11:53  $ gem install libv8 -v '3.16.14.3' -- --with-system-v8


Building native extensions with: '--with-system-v8'
This could take a while...
Successfully installed libv8-3.16.14.3
Parsing documentation for libv8-3.16.14.3
Installing ri documentation for libv8-3.16.14.3
Done installing documentation for libv8 after 0 seconds
1 gem installed


02:05  $ gem install therubyracer -v '0.12.1' -- --with-system-v8


Building native extensions with: '--with-system-v8'
This could take a while...
ERROR:  Error installing therubyracer:
    ERROR: Failed to build gem native extension.

    /usr/local/var/rbenv/versions/2.1.2/bin/ruby extconf.rb --with-system-v8
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
checking for v8.h... no
*** 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
    --without-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=/usr/local/var/rbenv/versions/2.1.2/bin/ruby
    --with-pthreadlib
    --without-pthreadlib
    --with-objclib
    --without-objclib
    --enable-debug
    --disable-debug
    --with-v8-dir
    --without-v8-dir
    --with-v8-include
    --without-v8-include=${v8-dir}/include
    --with-v8-lib
    --without-v8-lib=${v8-dir}/lib
/usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/libv8-3.16.14.3/ext/libv8/location.rb:50:in `configure': You have chosen to use the version of V8 found on your system (Libv8::Location::System::NotFoundError)
and *not* the one that is bundle with the libv8 rubygem. However,
it could not be located. please make sure you have a version of
v8 that is compatible with 3.16.14.3 installed. You may
need to special --with-v8-dir options if it is in a non-standard
location

thanks,
The Mgmt

    from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/libv8-3.16.14.3/lib/libv8.rb:7:in `configure_makefile'
    from extconf.rb:32:in `'

extconf failed, exit code 1

Gem files will remain installed in /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1 for inspection.
Results logged to /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/therubyracer-0.12.1/gem_make.out
Nicolas Blanco
  • 11,164
  • 7
  • 38
  • 49

18 Answers18

260
gem uninstall libv8
brew install v8
gem install therubyracer
gem install libv8 -v '3.16.14.3' -- --with-system-v8

this is the only way it worked for me on 10.10 (ruby 2.1.2)

Or try gem install libv8 -v 'XX.XX.XX' -- --with-system-v8 adding the version of the gem :)

UPDATE for Mac OS Catalina:

brew tap homebrew/versions
brew install v8@3.15
brew link --force v8@3.15
gem install libv8 -v 'XX.XX.XX' -- --with-system-v8
gem install therubyracer
Wylkon
  • 2,724
  • 2
  • 11
  • 8
  • 3
    Yep, this is the one that helps without any weirdness. Even though you may just be getting a libv8 error, do this! thanks. – pjammer Nov 02 '14 at 18:55
  • 2
    Yep. This is the right way to do it. Specially if you had rebuilt your ruby with the latest 10.10 command line tools. – Pankaj Tyagi Nov 06 '14 at 23:07
  • 3
    Worked for me with Ruby 2.1.3 in OS X Yosemite. – Sarah Vessels Nov 17 '14 at 16:21
  • this worked for 2.0.0! Thanks mate! now I'm facing another error. rmagick – olleh Mar 03 '15 at 08:24
  • 4
    In addition to this, If you are using bundler and have a Gemfile, you may need to adjust it to the latest version you just installed. For example, I had to (on OS X Yosemite) do the following: `gem 'therubyracer', '0.12.1'` (added the version). Then removed Gemfile.lock and did `bundle install`. It works fine. – paneer_tikka Apr 01 '15 at 12:33
  • 2
    This worked for me as well, on El Capitan. I think this is a lot simpler and should be the accepted answer. – rcd Dec 08 '15 at 22:32
  • I didn't need to do the brew bit. Simply running gem install libv8 -v '3.16.14.3' -- --with-system-v8 worked for me. – rardoz Mar 16 '16 at 18:02
  • 1
    Best Solutions for any mac, really thanks for therubyracer – AMIC MING May 19 '16 at 05:44
  • 1
    Worked like a charm on macOS Sierra (10.12.3) as well. – Jeremy J Barth Jan 27 '17 at 07:09
  • 1
    This worked for libv8-3.16.14.7 / therubyracer-0.12.1 with ruby 1.9.3p551 on High Sierra 10.13.6. Thanks! – joe Jul 31 '18 at 01:30
  • 1
    Worked for me in MacOS Mojave – Jeffrey M Castro Apr 16 '19 at 08:09
68
git clone https://github.com/cowboyd/libv8.git
cd libv8
bundle install
bundle exec rake clean build binary
gem install pkg/libv8-3.16.14.3-x86_64-darwin-12.gem #note that libv8 version may change, so tab through files in pkg/, also remember to use the one with version specified

then just bundle your project gems

this is the only way it worked for me on 10.10 (ruby 2.1.2)

mmln
  • 2,104
  • 3
  • 24
  • 33
  • 2
    thanks but this is libv8, i was speaking of therubyracer gem. – Nicolas Blanco Jul 31 '14 at 14:24
  • 2
    this is what you need to avoid issues with therubyracer – mmln Jul 31 '14 at 15:48
  • 2
    I don't care if I'm breaking the rules. I can't thank you enough. You have saved a huge project deadline for me. – RubyRedGrapefruit Oct 19 '14 at 16:51
  • 1
    Thank's, it work for me, just for copy/paste guy like me, we are now at gem install pkg/libv8-3.16.14.7-x86_64-darwin-14.gem – Christophe Dufour Oct 21 '14 at 09:58
  • Note that you can build the specific version you need by doing a `git checkout tags/v3.x.y.z` (where x, y, and z are the minor, etc., version numbers you need) after cloning. – duma Nov 07 '14 at 17:20
  • 2
    It's also worth mentioning that if you're using a Gemfile and still having trouble installing therubyracer, it's probably because there's a different version of libv8 that's already been added to the Gemfile.lock. Just add `gem 'libv8', '3.16.14.3'` (or whatever is the exact version of the libv8 that you just manually installed), and run bundle update libv8. That should then install therubyracer. – Jon Cairns Jan 13 '15 at 09:59
  • 1
    I having issues `compiling v8 for x64`. When I run 'bundle exec rake clean build binary' I get `Unable to find a compiler officially supported by v8. It is recommended to use GCC v4.4 or higher`. Any Ideas? – Luis D Urraca Jan 13 '15 at 11:19
  • Please also see the other answer below by Wylkon, with currently 214 votes which suggests installing v8 as well. This worked for me. – redfox05 Nov 22 '16 at 23:35
44

None of the answers work for me this time. I have too use this:

brew tap homebrew/versions
brew install v8-315

gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315

bundle install

Seen on the rubyracer Github issues.

Hope it helps someone else.

coding addicted
  • 3,422
  • 2
  • 36
  • 47
  • Thanks for this. None of the other approaches will work on El Capitan using modern versions of the dependent gems. (therubyracer is woefully behind libv8 at this point.) – Matt Mitchell Apr 20 '16 at 17:51
  • 1
    Sadly you're right... This error is driving me crazy each time I change ruby version. – coding addicted Apr 20 '16 at 17:54
  • 1
    tap homebrew/versions has now been deprecated so this no longer works. – mattp Dec 17 '19 at 20:22
  • 2
    Actually, `gem install therubyracer -- --with-v8-dir=$(brew --prefix v8-315)` works better for me. The dir in my mac is actually `/usr/local/opt/v8@3.15` – Junji Zhi Jul 18 '20 at 17:05
26

Maybe it will be useful for someone but I had problems installing therubyracer (because of the problems with libv8) the solution was to uninstall all the libv8 that I had installed. Install therubyracer

$ gem uninstall libv8
$ gem install therubyracer -v '0.12.0'
Fetching: libv8-3.16.14.7-x86_64-darwin-14.gem ( 57%)
Fetching: libv8-3.16.14.7-x86_64-darwin-14.gem (100%)
Successfully installed libv8-3.16.14.7-x86_64-darwin-14
Building native extensions.  This could take a while...
Successfully installed therubyracer-0.12.0
2 gems installed

I hope this helps someone.

Jakub Troszok
  • 99,267
  • 11
  • 41
  • 53
  • This seems to have worked for me. However I would like to point out that the best way to uninstall all versions of the libv8 gem is: `gem uninstall libv8 -a -x`. If you use a ruby version manager (e.g. `rbenv`, etc) then this works for only your current version of ruby (in case that wasn't obvious). – xentek Jan 26 '15 at 17:32
  • this solution worked for me - El Capitan 10.11.6, Ruby - ruby 1.9.3p448 (2013-06-27 revision 41675) – sameera207 May 25 '17 at 05:12
13

It seems like this has been fixed upstream. What worked for me and @aurels and @Mike Causer and @Juanda was:

bundle update libv8
Martin T.
  • 3,132
  • 1
  • 30
  • 31
7

This worked for me very well on my Yosemite and Ruby 2.1.5 (Ruby through RVM)

gem install libv8 -v '3.16.14.3' -- --with-system-v8

Earlier it was giving me error Gem::Ext::BuildError: ERROR: Failed to build gem native extension. for libv8 gem version 3.16.14.3

Rohan Daxini
  • 496
  • 4
  • 12
7

Only this works for me in my Yosemite, Ruby 2.1.2:

gem install libv8 -v '3.16.14.3' -- --with-system-v8
brew link --overwrite v8-315 --force
gem install therubyracer -v '0.12.2' -- --with-system-v8
aquajach
  • 2,548
  • 2
  • 23
  • 29
6

I was able to proceed with ruby racer after rm Gemfile.lock

beforehand: I installed v8 via brew install v8, and then did gem install libv8 -v '3.16.14.3' -- --with-system-v8

and I am running 10.10 Yosemite

CloudMagick
  • 2,428
  • 2
  • 23
  • 20
4

They have corrected this issue in the most recent version of libv8. See: https://github.com/cowboyd/libv8/issues/123

You should install from the github repo, in rails I added a line to my gemfile like this gem "libv8", git: "git://github.com/cowboyd/libv8.git", submodules: true

EDIT:

This apparently only solves some of the problem. I installed the new version of libv8, but now the rubyracer is still looking for the other one I think? Still looking into it.

Borromakot
  • 293
  • 1
  • 2
  • 13
3

I had the same issue on Yosemite. My solution is similar to what appears above.

Use gem uninstall libv8 to remove anything that might be installed.

Leave therubyracer in your Gemfile, but remove any explicit reference to libv8.

Run bundle install.

libv8 then installed fine as a dependency.

Martin Streicher
  • 1,983
  • 1
  • 18
  • 18
  • This was my issue. I had multiple version of libv8 fighting each other. Clearing them out and letting bundler resolve the dependency was the right thing to do. – DavidMann10k Jun 22 '15 at 17:27
2

Updated answer for 2018.

I'm on High Sierra, on Homebrew 1.6.1

brew install v8-315

gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8@3.15/

Is what worked for me.

Credit goes to @coding-addicted for his original answer.

alexggordon
  • 512
  • 6
  • 17
1

After hours of trying simply upgrading ruby worked:

brew install ruby 

and then adding the following to gem file:

gem 'libv8'  
gem 'therubyracer' 
Qiu
  • 5,651
  • 10
  • 49
  • 56
1

A heads up to anyone that might have been having my issue: I ended up uninstalling my ruby version in RVM and then reinstalling it. That seemed to use the correct dependancies in the latest version of xcode tools for compiling ruby.

rvm list
rvm uninstall ruby-x.x.x
rvm install ruby-x.x.x
colsen
  • 573
  • 5
  • 13
0

I did the following

gem install therubyracer

which now installs therubyracer 0.12.1 which installs the dependency libv8 (3.16.14.7 x86_64-darwin-14) which installed with no errors.

I did this using ruby 2.1.5 which I installed via:

CC=/usr/bin/gcc rbenv install 2.1.5

which I did after running brew upgrade ruby-builds.

After installing ruby 2.1.5, I also ran

gem upgrade --system

to get rubygems-update 2.4.5

Chris Beck
  • 1,899
  • 2
  • 19
  • 26
0

this happens due to some conflicts with the libv8 as well, although you can just assign a version to the rubyracer and it will be installed:

change the following in the gemfile:

gem 'therubyracer', '~> 0.12.1'

and do bundle install

abcd_win
  • 107
  • 1
  • 6
0

What worked for me, based on the following comment,

https://github.com/cowboyd/therubyracer/issues/304#issuecomment-62046085

was to remove Gemfile.lock and then run bundle install

tufla
  • 562
  • 6
  • 16
0

This solution worked for me following Jakub Troszok's solution above with just a minor change

gem uninstall libv8
gem install therubyracer -v '0.12.1'
    Fetching: libv8-3.16.14.19-x86_64-darwin-18.gem (100%)
    Successfully installed libv8-3.16.14.19-x86_64-darwin-18
    Building native extensions.  This could take a while...
    Successfully installed therubyracer-0.12.1
    Parsing documentation for libv8-3.16.14.19-x86_64-darwin-18
    Installing ri documentation for libv8-3.16.14.19-x86_64-darwin-18
    Parsing documentation for therubyracer-0.12.1
    Installing ri documentation for therubyracer-0.12.1
    Done installing documentation for libv8, therubyracer after 0 seconds
    2 gems installed
gem install libv8 -v '3.16.14.17' -- --with-system-v8  (if the libv8 version required for your project is different from the one installed by rubyracer)
bundle install
dchhatani
  • 31
  • 5
  • Please point out what the minor change is and try to explain why it's working. Since you're answering a 4 years old question, you should also add some detail on applicable versions (your answer might not have been relevant then). – Michal Nov 26 '18 at 02:20
0

Using homebrew's directory of v8 for --with-v8-dir=/usr/local/Cellar/v8@3.15/3.15.11.18_1, instead of /usr/local/opt/v8-315, is what worked for me, in coding addicted's answer.

This is visible in the Summary of the brew install command, brew install v8-315.

foamroll
  • 752
  • 7
  • 23