therubyracer - Gem::Ext::BuildError: ERROR: Failed to build gem native extension
Asked Answered
B

15

85

I'm trying to install the following gem versions on Mavericks

  • libv8 (3.16.14.3)
  • therubyracer (0.12.1)

Obviously therubyracer gems depends on libv8.

1) Installing libv8

What is libv8? My bit of research seems to indicaite it's some sort of javascript library used by Google Chrome?

I was having trouble installing it, but this great post had both my error and a well-explained answer on how to bypass it.

So I installed libv8 with

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

It's my understanding that this installs the gem but uses my local system installation of the v8 library instead of... the version that comes with the gem? Either way, it was successful.

2) Installing therubyracer

During the next step, I had trouble install therubyracer gem. I'm not quite sure what this gem does, just that it's a dependency of a rails project I'm trying to bundle install.

It gives me the following error:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/jeeves.butler/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
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
    --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/jeeves.butler/.rvm/rubies/ruby-1.9.2-p290/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
/Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/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 bundled 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 /Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/gems/libv8-3.16.14.3/lib/libv8.rb:7:in `configure_makefile'
    from extconf.rb:32:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/gems/therubyracer-0.12.1 for inspection.
Results logged to /Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/extensions/x86_64-darwin-13/1.9.1/therubyracer-0.12.1/gem_make.out

From what I can gather, I chose to install libv8 using my local V8 library instead of what was provided with libv8, but now that local installation could not be located.

  • How do I check if I do indeed have V8 installed and how do I locate it?
  • I tried a few of the specified flags, none of them seemed to point the gem to the correct installation directory
  • This might be a separate topic, but what is extconf.rb? I've seen it in a few places. And what's it trying to do with the gcc compiler in specific?

Thanks!!

EDIT:

  1. I tried this solution of uninstalling libv8 and re-installing via brew install. It was mentioned in a couple of similar questions as well. No luck.

  2. I also tried the CC, CXX, and CPP environment variables as described here, although I don't think that has any effect as it was already picking up my gcc v4.6 compiler.

Bet answered 8/5, 2014 at 8:44 Comment(2)
this this, maybe?Trichocyst
<sigh> i've always had trouble installing therubyracer on a mac =(Suborbital
F
167

This steps worked for me.

OS: Maverick Ruby: 2.1.1

gem uninstall libv8
gem install therubyracer -v '0.11.3'
gem install libv8 -v '3.11.8.13' -- --with-system-v8
Forewarn answered 4/9, 2014 at 7:40 Comment(4)
Accepting this answer, with one change. I switched steps 3 & 2 to make it work - install libv8 and then install theruby racer. Thanks!Bet
Thanks, that worked like a charm! I must be getting tired, but it would be helpful if your instructions had sharps instead of your version numbers, I needed to install different versions, but I simply copies your notes.Capetian
Note the libv8 version is critical, as noted here that odd point release (the last two digits in the version) contains the binary as well.Honeysucker
The install/uninstall/reinstall dance worked for me on Mojave. I hate this old stuff! :DBrachylogy
H
76

For those facing this problem in OS X El Capitan, this solution from a therubyracer issue thread was what finally worked for me:

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

I had also run brew install gcc prior, but I'm not sure whether this was in fact necessary.

Hierogram answered 28/3, 2016 at 21:33 Comment(6)
I had to delete my Gemfile.lock before it finally worked. Thx for the hint.Archaic
+1, but for future readers, you'll want to gem install libv8 -v 'A.B.C.D' as appropriate. It's 3.16.14.15 as of this writing.Dwarf
+1, In case you want to install specific version of therubyracer use: gem install therubyracer -v 'x.x.x' -- --with-v8-dir=/usr/local/opt/v8-315Stratovision
Looks a lot like jottr's answer. Maybe throw him a shout out.Quirk
For me, the v8 dir was: /usr/local/opt/[email protected]Ornithorhynchus
Great, worked for me as well. Just uninstall all prev versions of libv8Timework
S
26

Try first uninstalling libv8 gem, then install rubyracer, and then libv8

gem uninstall libv8
gem install therubyracer
gem install libv8 -- --with-system-v8
Superficies answered 8/5, 2014 at 19:29 Comment(2)
No luck :( The following lines from the error seemed interesting: g++-4.6: error: x86_64: No such file or directory g++-4.6: error: unrecognized option '-arch'Bet
I've found that installing libv8 before therubyracer works better.Dorsum
H
24

Tertom's solution posted on github solved it for me, after having tried all other solutions proposed on the respective github issue and here.
I had the exact same system configuration.
This is on el capitan, so not an exact answer to the question, but people might find this info helpful.

I'm citing it here for visibility:

Solved the same problem

  • MacOS 10.11.2
  • ruby 1.9.3
  • libv8 3.16.14.13
  • therubyracer 0.12.2

--

brew tap homebrew/versions  
brew install v8-315  
brew link --force v8-315  
bundle install  
brew unlink v8-315

If you also cannot install libv8,

gem install libv8 --with-system-v8

or

bundle config build.libv8 --with-system-v8
Hoogh answered 22/1, 2016 at 22:2 Comment(4)
This worked for me. I found I needed to specify the version of libv8 gem that rubyracer expected to install.Secund
Yeah I believe bundle config build.libv8 --with-system-v8 was the key for me. Thanks!Playhouse
This was the only thing that worked for me (and trying in late 2019 on Catalina)Mound
Very helpful, even though homebrew/versions was deprecated. My problem was that my current link was linked to '/usr/local/bin/d8'. Unlinking that and running brew link --force v8-315 worked for me. 2/2020 -- MacOS 10.15.3. -- Ruby version 1.9.3 -- Bundler 1.16.4 -- libv8 version 13.16.14.19Twana
W
15

For all of you out there using macOS 10.15, brew has has changed so you will need to do these commands.

brew install [email protected]
gem install libv8 -v 'YOUR_VERSION' -- --with-system-v8
gem install therubyracer -v 'YOUR_VERSION' -- --with-v8-dir=/usr/local/opt/[email protected]
bundle install
Wallah answered 6/11, 2019 at 19:28 Comment(0)
O
6

The above answers did not work for me; my bundler config has disable-shared-gems enabled which causes additional issues.

I'm using Yosemite 10.10.1, Rails 3.2.x, and Ruby 1.9.3p550.

The following snippet in my bin/setup has fixed the issue for me.

if ! bundle show therubyracer; then
    bundle config build.libv8 --with-system-v8
    gem install --install-dir vendor/bundle libv8 -v 3.16.14.7
    gem install libv8 -v 3.16.14.7
    gem install --install-dir vendor/bundle therubyracer 
fi
Orthotropous answered 18/12, 2014 at 12:0 Comment(0)
D
4

I found a workaround to the above problem.

This is more of a compatibility among libv8 and therubyracer.

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

gem install therubyracer -v '0.10.2'

This should work fine as both the versions are compatible with me. Initially I was trying to install the version 0.12.0 for therubyracer and was facing the issue. Once I switched to version 0.10.2, everything worked fine.

My current OS: Mavericks

Dubitable answered 26/8, 2014 at 7:9 Comment(0)
P
4

I've got this issue for MacOS Mojave 10.14.2 and I was able to fix this issue when I found where package v8-315 was installed and what the folder name was. In my case, it was here /usr/local/opt/[email protected].

To fix this, I've run next:

brew install v8-315
gem install libv8 -v '3.16.14.15' -- --with-system-v
gem install therubyracer -v '0.12.2' -- --with-system-v8 --with-v8-dir=/usr/local/opt/[email protected]
bundle install
Papillote answered 16/1, 2019 at 20:59 Comment(0)
G
2

In my Case

MacOS: Catalina, Ruby: 2.3.3, Using rbenv (not RVM), I Required therubyracer version : 0.12.3 (Does not matter)

I tried all the solution but what worked for me, Dear pls do not blindly copy paste solution (bcz I did in my case), first read and then change the versions in the below commands if you need any. Most of the commands are common in most of the exisiting answers but what worked for me gem install therubyracer -- --with-v8-dir=$(brew --prefix v8-315) instead of gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315 Thanks to Junji Zhi for his comment in this answer

1. brew install gcc
2. brew tap homebrew/versions   (If it wont work then below 2 steps, for latest MacOS version)
2.a. brew tap brewsci/bio
2.b. brew tap brewsci/science
3. brew install v8-315     (uninstall if v8 installed previously without '-315')
4. gem install libv8 -v '3.16.14.19' -- --with-system-v8   (Be careful with the libv8 version mentioned in this command, replace version number with one required)
5.a. gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315    (If it does not work then try below one, In my case below command worked)
5.b. gem install therubyracer -- --with-v8-dir=$(brew --prefix v8-315)

Done, then continue with your bundle install

Note: While gem install therubyracer, check for which version of libv8 is being installing, if it is diffrent than what i mentioned in the step 4 then, your therubyracer may not install, so just do one thing, gem uninstall libv8 then repeat step-4 by changing the version, what you can see in the console while installing therubyracer

Globefish answered 13/8, 2020 at 9:16 Comment(0)
A
2

The commands below solved it for me in Catalina with bundler

$ brew install [email protected]
$ bundle config build.libv8 --with-system-v8
$ bundle config build.therubyracer --with-v8-dir=$(brew --prefix [email protected])
$ bundle install
Aerodonetics answered 15/12, 2020 at 4:51 Comment(0)
D
1

After breaking my head for almost two days this worked for me.

rvm install 2.2.2
gem install rails
bundle install
Dine answered 9/10, 2015 at 18:34 Comment(0)
M
1

I couldn't get therubyracer to build on macOS Catalina 10.15 due to the libv8 dependency, despite installing the x64 (64-bit variant) of libv8.

The solution for me, was to switch from therubyracer to mini_racer, the mini_racer gem installed (without needing to build locally) and, hey presto! I could continue.

Try it!

Maddening answered 14/10, 2019 at 15:1 Comment(1)
Except when your project requires LESS files to be compiled to CSS :/Bauble
K
1

This has worked for me:

gem install libv8 -v '3.16.14.17' -- --with-system-v8
brew install v8-315
gem install therubyracer -v '0.12.3' --source 'http://rubygems.org/' -- --with-v8-dir='/usr/local/opt/[email protected]'

For the last command check the output of brew --prefix v8-315 in my case it was /usr/local/opt/[email protected].

Kuenlun answered 28/8, 2020 at 21:10 Comment(0)
B
-2

I noticed that when we encounter a problem:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension

You should then install build-essential

sudo apt install build-essential

It works for me with mini_race's installation problems.

Billye answered 24/8, 2017 at 18:20 Comment(0)
H
-3

I just run bundle update, and it worked for me.

Obs.: Using Ruby 2.3.0

Homeopathy answered 10/5, 2016 at 0:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.