28

bundle install fails with Make sure that `gem install therubyracer -v '0.12.1'` succeeds before bundling

gem install therubyracer -v '0.12.1' fails with errors which appear to relate to compilation

Prior to this, libv8 gem was having problems but that is now installed thanks to following SO posts.

Guides for fixing rubyracer for Mavericks seem to not work, due to changes in El Capitan?

ln: /usr/bin/cpp: Operation not permitted 
Community
  • 1
  • 1
xxjjnn
  • 14,591
  • 19
  • 61
  • 94

10 Answers10

93
  1. Install xcode through app store
  2. Install 'command line tools' for xcode (xcode-select --install)
  3. If using rbenv, after installing ruby you needed rbenv rehash
  4. Assuming you have run gem install bundler and got errors, remove your mess:

    gem uninstall libv8
    gem uninstall therubyracer
    brew rm v8
    
  5. Install gcc4.2

    brew tap homebrew/dupes
    brew install apple-gcc42
    
  6. Install v8

    brew tap homebrew/versions
    brew install v8-315
    brew link --force v8-315
    
  7. Install gems

    gem install libv8 -- --with-system-v8
    gem install therubyracer
    

    if you get dyld: lazy symbol binding failed: Symbol not found, @rpbaltazar suggests an alternative:

    bundle config --local build.libv8 --with-cxx=/usr/local/bin/g++-4.2
    bundle install
    
xxjjnn
  • 14,591
  • 19
  • 61
  • 94
  • 1
    This solved the problem for me. After several other involved methods, I think the key difference with this answer was simply providing the "old" compiler (GCC). Thank you. – Aeschylus Nov 12 '15 at 22:52
  • 1
    I only needed to do step #7. – Catfish Jan 18 '16 at 15:08
  • 1
    there was great pain and then there was this answer. THANK YOU! – don.najd Jan 27 '16 at 01:29
  • 1
    I take it back.. now I'm getting a different error dyld: lazy symbol binding failed: Symbol not found: __ZN2v82V821AddGCPrologueCallbackEPFvNS_6GCTypeENS_15GCCallbackFlagsEES1_ Referenced from: /development/opensource/rails-loaded/vendor/ruby/2.1.0/extensions/x86_64-darwin-15/2.1.0-static/therubyracer-0.12.2/v8/init.bundle Expected in: flat namespace – don.najd Jan 27 '16 at 20:04
  • This should contain why it works. Uninstall and Install it completely is not really a good answer at all. – b1nary Feb 15 '16 at 08:28
  • Trial and error after reading dozens of SO posts with suggestions. To the best of my knowledge: [EXPLANATION](http://itisamystery.com/) – xxjjnn Feb 15 '16 at 10:46
  • @don.najd I'm facing the same problem. Did you manage to solve this? – Saurabh Nanda Mar 14 '16 at 10:44
  • People with problems - is there anything special about your setup? Are you using a Hackintosh? I cannot reproduce I am sorry =( I think I read somewhere that dyld changes might not take effect until reboot, could you try reboot and I'll add it as a step if it works? – xxjjnn Mar 14 '16 at 13:45
  • I did work it out and I'm ashamed to say I can't remember how. I want to say it was all related to GCC version. I am kicking myself for not coming back here and updating you all. @Zero – don.najd Mar 15 '16 at 17:28
  • @xxjjnn my laptop was stock mac, brand new & el capitan – don.najd Mar 15 '16 at 17:28
  • Found the answer that worked for me!!! http://stackoverflow.com/questions/33343159/gem-install-therubyracer-v-0-11-4?rq=1 – don.najd Mar 24 '16 at 20:23
  • Great thanks, the realy helpful answer. One from thousands that helped. – Artyom Kalmykov Jun 10 '16 at 10:28
51

I still had issues with @xxjjnn's answer. The following answer from github resolved it. My current setup: El Capitan 10.11.4 and Xcode 7.3.

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
Phil Tran
  • 511
  • 4
  • 3
  • Worked for on El Capitan 10.11.3 – Conor Apr 10 '16 at 12:31
  • 2
    Worked on OS X 10.11.4 w/ Ruby 2.3.0 and Rails 4.2.6 - [Process](https://gist.github.com/cdesch/35e7c2fe1abaa8894e7aa963c3bcb41d) – DogEatDog Apr 11 '16 at 12:41
  • 1
    Worked for me on OS X 10.11.4 Ruby 2.3.0, Rails 4.2.6 too. I tried various other approaches, this is the only one which solved the 'therubyracer' compile issue for me after I upgraded to Ruby 2.3.0 – smile2day Apr 12 '16 at 14:05
  • "gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315" saved me time! – mike927 Jan 16 '18 at 09:45
  • Despite the fact that homebrew/versions doesn't do anything these days, this solution basically worked for my on Catalina with the following changes: I had to specify libv8 3.16.14.19 instead of 3.16.14.13; and --with-v8-dir=/usr/local/opt/v8@3.15 as opposed to without the @ sign. I was using Ruby 2.4.6 and Rails 4.2.11.1 on Catalina 10.15.2. – John Messenger Dec 26 '19 at 12:24
11

The answer provided on therubyracer Github page worked for me:

brew tap homebrew/versions
brew install v8-315
brew link --force v8-315
gem install libv8 -- --with-system-v8
gem install therubyracer
Jan Klimo
  • 4,643
  • 2
  • 36
  • 42
5

I updated the gem therubyracer to 0.12.2, then I runned this commands in the rails repository:

$ brew install v8-315
$ bundle config --local build.libv8 --with-system-v8
You are replacing the current local value of build.libv8, which is currently nil
$ bundle config --local build.therubyracer --with-v8-dir=$(brew --prefix v8-315)
You are replacing the current local value of build.therubyracer, which is currently nil

and finally

bundle install
anquegi
  • 11,125
  • 4
  • 51
  • 67
3

I know this question is specifically about installing therubyracer -v '0.12.1', but the solution really is to upgrade to '0.12.2'.

I've struggled with this on a few projects and always forget that. Then eventually I remember and it all works.

Be sure to clean out anything you've added to bundle config once you don’t need it with bundle config --delete build.libv8.

Here’s the thread on the gem repo about this: https://github.com/cowboyd/therubyracer/issues/398#issuecomment-238161167

equivalentideas
  • 325
  • 3
  • 15
2

(Posting as a comment for readability purposes, but this should be an add-on to the original accepted answer)

After running the accepted answer, I was facing the error described in the comments.

The solution I found helpful for me was running the following

gem uninstall libv8
gem uninstall therubyracer
bundle config --local build.libv8 --with-cxx=/usr/local/bin/g++-4.2
bundle install

Please note that the initial steps of the accepted answer are necessary, namely installing the compiler.

rpbaltazar
  • 801
  • 7
  • 15
  • I've nuked the ruby version and followed these instructions exactly and still get the "dyld: lazy symbol binding failed: Symbol not found" error. Any more insight here @rpbaltazar – equivalentideas Aug 08 '16 at 06:34
  • hey. in which version are you having the problem? the steps described worked for me in el capitan. unfortunately without facing the problem myself i find it hard to solve as a lot of this was done by trial and error. – rpbaltazar Aug 13 '16 at 04:02
2

Actually, apple-gcc42 is removed from brew:

apple-gcc42 was deleted from homebrew/core in commit bcba321ea:

Instead, I've installed gcc@4.9 So, following xxjjnn answer, instead of 5 just run:

brew install gcc@4.9
Andrew
  • 21
  • 2
1

First try to delete your Gemfile.lock and run bundle install again. Gemfile.lock will be created again.

This will work for most cases on El Capitan.

Without that it will just install the same versions mentioned in Gemfile.lock. If you delete this file, bundle install will fetch newest versions of your gems.

Sven R.
  • 1,049
  • 17
  • 24
0

If none of the above works for you, follow this guys advice. Uninstalling everything related and upgrading gcc fixed it for me.

Gem install therubyracer -v '0.11.4'?

Community
  • 1
  • 1
don.najd
  • 630
  • 6
  • 12
0

If you can switch to mini racer, installing it or updating it worked for me similar to this post

How to fix libv8 bad version error

TL;DR bundle update mini_racer

Marty
  • 582
  • 4
  • 17