6

How do I install libv8 gem? I can't install libv8 gem. When I try, I get the below error.

$ gem install libv8
Building native extensions.  This could take a while...
ERROR:  Error installing libv8:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby.exe extconf.rb
creating Makefile
Using compiler: /usr/bin/g++
which: no gmake in (/usr/local/bin:/usr/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/WINDOWS/system32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files/Microsoft SQL Server/100/Tools/Binn/VSShell/Common7/IDE:/cygdrive/c/Program Files/Microsoft SQL Server/100/Tools/Binn:/cygdrive/c/Program Files/Microsoft SQL Server/100/DTS/Binn:/cygdrive/c/Program Files/Heroku/bin:/cygdrive/c/Program Files/ruby-1.9.2/bin:/cygdrive/c/Program Files/git/bin:/cygdrive/c/Program Files/git/cmd:/cygdrive/c/Program Files/DTN/IQFeed:/cygdrive/c/Program Files/OpenVPN/bin:/cygdrive/c/Program Files/Java/apache-ant-1.8.3/bin:/usr/lib/lapack:/cygdrive/c/Program Files/Notepad++:.:/cygdrive/c/Program Files/Java/android-sdk/platform-tools/:/cygdrive/c/Program Files/Java/android-sdk/tools/:/cygdrive/c/Program Files/Java/jdk1.7.0_03/bin)
In file included from ../src/conversions-inl.h:42:0,
                 from ../src/conversions.cc:32:
../src/platform.h:77:12: error: new declaration ‘int random()’
/usr/include/cygwin/stdlib.h:29:6: error: ambiguates old declaration ‘long int random()’
make[1]: *** [/usr/lib/ruby/gems/1.9.1/gems/libv8-3.11.8.13/vendor/v8/out/ia32.release/obj.target/preparser_lib/src/conversions.o] Error 1

I tried to use

$ gem install libv8 --pre
Fetching: libv8-3.5.10.beta1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed libv8-3.5.10.beta1
1 gem installed

But bundle install still would not run. It still tried to install version 3.11.8.13.

Installing libv8 (3.11.8.13) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

libv8 gem is not in my Gemfile. I don't know how to find out what is trying to use it, but while searching I saw that rubyracer uses libv8 and I do have

group :assets do
  gem 'therubyracer', :platform => :ruby

I even tried to edit the /usr/lib/ruby/gems/1.9.1/gems/libv8-3.11.8.13/src/platform.h file and comment out line 77:

//int random();

But when I ran gem install libv8, it overwrote my changes and still gave an error. I saw a trick in gem install libv8 --help, so I edited the file again and commented out line 77, and tried

cd /usr/lib/ruby/gems/1.9.1/gems/libv8-3.11.8.13/vendor/v8
make

However, that just gave different errors:

In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api/winsock2.h:56:0,
                 from ../src/win32-headers.h:77,
                 from ../src/platform-win32.cc:31:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api/psdk_inc/_fd_types.h:100:2: warning: #warning "fd_set and associated macros have been defined in sys/types.      This can cause runtime problems with W32 sockets"
In file included from ../src/win32-headers.h:80:0,
                 from ../src/platform-win32.cc:31:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api/wspiapi.h:26:41: error: expected ‘>’ before numeric constant
../src/platform-win32.cc: In function ‘int random()’:
../src/platform-win32.cc:122:12: error: new declaration ‘int random()’
/usr/include/cygwin/stdlib.h:29:6: error: ambiguates old declaration ‘long int random()’
Chloe
  • 25,162
  • 40
  • 190
  • 357
  • you can just install nodejs into your cygwin and use command `gem install libv8 -v 'version_if_needed' -- --with-system-v8` – Kirill Warp Jul 28 '16 at 06:15

3 Answers3

4

I feel like there should be an answer for people who just want the error to go away so they can get on with learning rails.

It seems that you don't need 'therubyracer' specifically -- you can choose some other javascript engine.

Specifically, open the file Gemfile, and change 'therubyracer' to 'therubyrhino'. (If rhino doesn't work, there are more options and advice at: https://github.com/sstephenson/execjs#readme

Jon Carter
  • 2,836
  • 1
  • 20
  • 26
1

Since your question mentioned Cygwin, I assume you are Windows user. Currently, there's no way to install therubyracer or libv8 in Windows as said by its maintainer: therubyracer gem on windows. Windows is not Rails land unfortunately.

If you do need libv8, you can try nodejs instead. It comes with a binary, handy for all platform.

Community
  • 1
  • 1
kasperite
  • 2,460
  • 1
  • 15
  • 17
  • It works in RailsInstaller.org for Windows. I can run `bundle install` and `rails console`. However, that gem is not installed in that environment either `gem list therubyracer`. So how can I stop `bundle install` from trying to install it? – Chloe Feb 12 '13 at 03:15
  • 1
    BTW I was able to install libv8 3.11.8.0. I just kept decreasing the # until it worked: `gem install libv8 -v 3.11.8`. – Chloe Feb 12 '13 at 03:16
  • 1
    you can put that gem inside a group say `example` and run `bundle install --without example`. Bundle will simply ignore it – kasperite Feb 12 '13 at 03:25
  • Wow that worked! `bundle install --without assets`. So how do I find which item is using therubyracer? Is this correct? `find . -name \*.rb | xargs grep therubyracer` – Chloe Feb 12 '13 at 03:34
  • what rails version are you using?if you post the Gemfile, I might be able to answer. Rails 3.1.x onwards requires javascript runtime so most likely it's the reason why you need therubyracer – kasperite Feb 12 '13 at 03:38
  • there you go, `Rails 3.2.12` :D, Windows doesn't have javascript runtime so you will have to install either therubyracer, nodejs or similar for assets pipeline precompiling. You can disable the assets pipeline though, but that also means you missed out a big feature in Rails 3.2 – kasperite Feb 12 '13 at 03:50
  • Oh ok. Is there a way to force therubyracer to use the version of libv8 that did work? `gem list libv8`, `libv8 (3.11.8.0)`. It keeps trying to install the latest. – Chloe Feb 12 '13 at 04:02
  • 1
    Im pretty sure, It won't work:D(I was using Windows and did what you had done by decreasing libv8 version). Problem is therubyracer only started to include libv8 from version 3.11.8.5 and above. You can check it from here:https://rubygems.org/gems/therubyracer/versions/0.11.1beta1. It's a deadlock Im afraid. – kasperite Feb 12 '13 at 04:15
1

I've just hit the very same problem on my Win7 dev machine. It looks like installing https://github.com/hiranpeiris/therubyracer_for_windows and adding gem 'therubyracer' to the Gemfile sorts things out.

Before:

$ rails generate
c:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
(...)

This basically means that Rails needs rubyracer and therefore libv8.

After:

$ rails generate
    SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
    This poses a security threat. It is strongly recommended that you
    provide a secret to prevent exploits that may be possible from crafted
    cookies. This will not be supported in future versions of Rack, and
    future versions will even invalidate your existing user cookies.

    Called from: c:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.

Usage: rails generate GENERATOR [args] [options]
(...)
Jakub Czaplicki
  • 1,787
  • 2
  • 28
  • 50
  • Cool. There's also this Javascript interpreter, which is what I use for my Windows version (not Cygwin) of Ruby http://nodejs.org/ – Chloe Feb 23 '13 at 07:49