26

I recently wanted to update my gem bundle but ran into installation problems with libv8 (requirement for therubyracer):

Installing libv8 (3.3.10.3) with native extensions /usr/local/rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:552:in `rescue in block in build_extensions': ERROR: Failed
 to build gem native extension. (Gem::Installer::ExtensionBuildError)

        /usr/local/rvm/rubies/ruby-1.9.3-head/bin/ruby extconf.rb 
Checking for Python...*** 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.

I have found the issue report on therubyracer github site and it suggests to uninstall and reinstall libv8, but this does not work on my Ubuntu 11.04 machine. Any ideas - or am I stuck with the old version for a while?

John Bachir
  • 22,495
  • 29
  • 154
  • 227
emrass
  • 6,253
  • 3
  • 35
  • 57

7 Answers7

29

I had a similar issue on my good old Ubuntu 10.04 (x64)

After I updated the project Gemfile had those gems

  gem 'libv8', '~> 3.11.8'
  gem "therubyracer", '>= 0.11.0beta1', :require => 'v8'

But when I ran 'bundle install' I got an error

Installing therubyracer (0.11.0beta1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /home/sseletskyy/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for main() in -lpthread... yes
creating Makefile

make
compiling array.cc
compiling script.cc
compiling object.cc
compiling constants.cc
compiling signature.cc
compiling value.cc
compiling locker.cc
compiling init.cc
compiling heap.cc
compiling date.cc
compiling message.cc
compiling accessor.cc
compiling context.cc
compiling exception.cc
compiling backref.cc
compiling trycatch.cc
compiling gc.cc
compiling handles.cc
compiling stack.cc
compiling template.cc
compiling function.cc
compiling primitive.cc
compiling rr.cc
compiling v8.cc
compiling invocation.cc
compiling string.cc
compiling external.cc
compiling constraints.cc
linking shared-object v8/init.so
/home/sseletskyy/.rvm/gems/ruby-1.9.3-p194/gems/libv8-3.11.8.2-x86_64-linux/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a: could not read symbols: No such file or directory
collect2: ld returned 1 exit status
make: *** [init.so] Error 1


Gem files will remain installed in /home/sseletskyy/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.11.0beta1 for inspection.
Results logged to /home/sseletskyy/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.11.0beta1/ext/v8/gem_make.out
An error occured while installing therubyracer (0.11.0beta1), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.11.0beta1'` succeeds before bundling.

Here's a list of steps which worked for me to solve that block quickly

  1. Uninstall all versions of gems 'libv8' and 'therubyracer'

    > gem uninstall therubyracer

    > gem uninstall libv8

  2. Install therubyracer manually

    > gem install therubyracer

    Fetching: libv8-3.3.10.4-x86_64-linux.gem (100%) Fetching: therubyracer-0.10.1.gem (100%) Building native extensions. This could take a while... Successfully installed libv8-3.3.10.4-x86_64-linux Successfully installed therubyracer-0.10.1 2 gems installed Installing ri documentation for libv8-3.3.10.4-x86_64-linux... Installing ri documentation for therubyracer-0.10.1... Installing RDoc documentation for libv8-3.3.10.4-x86_64-linux... Installing RDoc documentation for therubyracer-0.10.1...

  3. Check versions of installed gems

    > gem list | grep libv

    libv8 (3.3.10.4 x86_64-linux)

    > gem list | grep therubyracer

    therubyracer (0.10.1)

  4. Set those versions in Gemfile and run

    > bundle install

  5. Summary. Well I understand that in my case I used not the latest versions and it could be bad for compatibility sake. But at least I could continue development.

Sergiy Seletskyy
  • 16,236
  • 7
  • 69
  • 80
  • 1
    Did not experience this issue ever since, but sounds like a valid workaround. Thanks for sharing. – emrass Jul 02 '12 at 22:07
  • 2
    Manually removing and installing like this is the only thing that worked for me, too. I can't figure out why letting Bundler install the gems causes trouble, but when I do it manually like this everything's fine. – Jim Stewart May 19 '13 at 23:52
  • It's very interesting to follow how 2 years old answer is still actual for people. Two more votes and I will beat the approved answer :) – Sergiy Seletskyy Feb 03 '14 at 21:31
  • You are the best! Thanks. Helped a lot – Yurii Halapup May 13 '19 at 23:07
29

Try that one for a little while:

gem 'therubyracer'
gem 'libv8', '3.16.14.3'

Should help.

Also it's better with a new bundler: gem install bundler --pre

tewathia
  • 6,890
  • 3
  • 22
  • 27
Dmitry Polushkin
  • 3,283
  • 1
  • 38
  • 44
  • This indeed solves the issue, thanks for all your help, Dmitry. Also, it seems like a version 3.3.10.3 is in the making. Was probably just bad timing to run "bundle update" this evening ... – emrass Nov 14 '11 at 20:38
  • I had libv8 version 3.16.14.7, downgrading the gem to 3.16.14.3 worked for me. Thanks! – dusan May 08 '15 at 15:06
  • This solved my issue with compiling on OS X 10.10.4. Thanks! – Greg Benedict Jul 28 '15 at 13:10
7

Ubuntu 11.04

gem "therubyracer", '0.11.1'
gem 'libv8'
  1. Uninstall therubyracer and libv8 gem

  2. Update the bundler gem version

  3. Install lib8-dev package

    sudo apt-get install libv8-dev

  4. Then run this

    sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion imagemagick graphicsmagick libmagickcore-dev libmagickwand-dev

  5. Now install therubyracer manually

    gem install therubyracer

  6. It will install therubyracer and libv8 for you.

  7. Now run bundle install

All above steps solved my problem :)

rohitkadam19
  • 1,734
  • 5
  • 21
  • 39
1

I've run into the same issue recently. Here is a bit of helpful information from the RoR.org 'Getting Started with Rails' Guide:

Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the absence of a runtime will give you an execjs error. Usually Mac OS X and Windows come with a JavaScript runtime installed. Rails adds the therubyracer gem to Gemfile in a commented line for new apps and you can uncomment if you need it. therubyrhino is the recommended runtime for JRuby users and is added by default to Gemfile in apps generated under JRuby. You can investigate about all the supported runtimes at ExecJS.

Based on what I've read elsewhere it seems that Windows support for the therubyracer gem is not there in the '3.3.10.4' version (possibly there in a more recent version, didn't read in that far though). I've installed python 2.7 and got it to compile but you still get errors later during the environment setup process.

So it comes down to this. Check out therubyracer documentation here. 'therubyracer' provides these features (:

  • Evaluate Javascript from with in Ruby
  • Embed your Ruby objects into the Javascript world
  • Manipulate JavaScript objects and call JavaScript functions from Ruby
  • API compatible with the The Ruby Rhino (for JRuby: http://github.com/cowboyd/therubyrhino)

If you ABSOLUTELY REQUIRE those features then you should switch to *nix and drop Windows for a development/production environment. Otherwise you can do what I did and choose not to install 'therubyracer' or 'libv8' (removed from my Gemfile). I don't rely heavily on JavaScript with the site I'm experiencing this problem with, so I just ignored both gems and all seems well (so far).

Hope this helps someone else in need!

TwoByteHero
  • 219
  • 3
  • 4
1

Ubuntu 12.04

gem 'libv8', '3.11.8.3'
gem 'therubyracer', '0.11.0beta5'

Specifying the versions above solved my problem with therubyracer.

Also as someone above suggested, I used the latest bundler:

gem install bundler --pre
Andrei
  • 1,121
  • 8
  • 19
0

Be sure to reference ruby in your Gemfile

gem 'therubyracer', :platform => :ruby

and then run bundle update.

sebastianwagner
  • 399
  • 2
  • 9
0

Using these terminal commands fixed it for me on Ubuntu 16.04

sudo apt-get install g++
sudo apt-get install build-essential
colonelclick
  • 2,165
  • 2
  • 24
  • 33
user3487016
  • 109
  • 2
  • 2
  • 6