bundle install / update: libv8 (therubyracer) installation fails (with native extensions) - ruby-on-rails

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?

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

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
Uninstall all versions of gems 'libv8' and 'therubyracer'
> gem uninstall therubyracer
> gem uninstall libv8
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...
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)
Set those versions in Gemfile and run
> bundle install
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.

Ubuntu 11.04
gem "therubyracer", '0.11.1'
gem 'libv8'
Uninstall therubyracer and libv8 gem
Update the bundler gem version
Install lib8-dev package
sudo apt-get install libv8-dev
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
Now install therubyracer manually
gem install therubyracer
It will install therubyracer and libv8 for you.
Now run bundle install
All above steps solved my problem :)

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!

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

Be sure to reference ruby in your Gemfile
gem 'therubyracer', :platform => :ruby
and then run bundle update.

Using these terminal commands fixed it for me on Ubuntu 16.04
sudo apt-get install g++
sudo apt-get install build-essential

Related

debase gem is exploading in my face on install

So I'm trying to install debase in my gemfile and explosions are happening. Here's what the output looks like...
(Ok so there was a bunch of stuff here that I removed cause it got fixed. Now I have only this remaining error)
UPDATE 2:
...installing ruby-debug19 helped to install vm_core.h (thank you to Alter Lagos for recommending that). Now I have a new error message...
Fetching debase 0.2.1
Installing debase 0.2.1 with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/fonso/.rbenv/versions/1.9.3-p551/bin/ruby extconf.rb
checking for vm_core.h... yes
creating Makefile
make
compiling breakpoint.c
In file included from breakpoint.c:1:0:
./debase_internals.h:5:24: fatal error: ruby/debug.h: No such file or directory
compilation terminated.
make: *** [breakpoint.o] Error 1
Gem files will remain installed in /home/fonso/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/debase-0.2.1 for inspection.
Results logged to /home/fonso/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/debase-0.2.1/ext/gem_make.out
An error occurred while installing debase (0.2.1), and Bundler cannot continue.
Make sure that `gem install debase -v '0.2.1' --source 'http://rubygems.org/'` succeeds before bundling.
In Gemfile:
debase
Anyone know how to solve this mystery?
"Failed to build gem native extension" means your computer had to compile a C extension to install the gem. This is actually common. Many gems like pg include C extensions. It's also common for people to encounter this error message. It just means your operating system lacks a certain package that would provide the C files needed to compile the extension.
The errors can be tricky to solve though because it's not a matter of changing what you're doing. You're installing the gem just fine. It's your environment that needs to be changed. You need to know which packages to install for your operating system for that version of the Gem.
Many tutorials include lists of packages you should install. For example, https://gorails.com/setup/ubuntu/18.04 tells you that, if you're installing the latest version of Ruby right now (3.0.1), you install: git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
These instructions are meant for Ubuntu 18.04. It would be different if you were using a different version of Ubuntu or a different operating system like MacOS. Also, your question shows you using a very old version of Ruby, 1.9.3. If you must use this old version, this could make this even harder for you, because there's no guarantee you'll find system packages that would work with the C extension that version of that gem wants to compile. I'd suggest using a recent version of Ruby if you can.
Annnnnd the answer is...For old apps using ruby 1.9.x use
gem 'ruby-debug-base19x', '~> 0.11.32'
instead of
gem debase
in your Gemfile per the readme for ruby-debug-ide https://github.com/ruby-debug/ruby-debug-ide
Now the gems install fine.
rdebug-ide command is not working tho', I've posted that question here... ruby-debu-ide command exploading in my face

Postgresql gem install pg 0.18.4 passes, bundle install fails

Mac OS El Capitan
Bundle install fails with:
compiling pg_connection.c
pg_connection.c:2394:3: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration]
gettimeofday(&currtime, NULL);
^
1 warning generated.
compiling pg_copy_coder.c
compiling pg_errors.c
compiling pg_result.c
compiling pg_text_decoder.c
compiling pg_text_encoder.c
compiling pg_type_map.c
compiling pg_type_map_all_strings.c
compiling pg_type_map_by_class.c
compiling pg_type_map_by_column.c
compiling pg_type_map_by_mri_type.c
compiling pg_type_map_by_oid.c
compiling pg_type_map_in_ruby.c
compiling util.c
linking shared-object pg_ext.bundle
ld: file not found: dynamic_lookup
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_ext.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/jmintz/Documents/LaunchAngels/radar/vendor/bundle/gems/pg-0.18.4 for inspection.
Results logged to /Users/jmintz/Documents/LaunchAngels/radar/vendor/bundle/extensions/x86_64-darwin-15/2.2.0-static/pg-0.18.4/gem_make.out
...
...
An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.
Running 'gem install pg -v '0.18.4' results in:
Building native extensions. This could take a while...
Successfully installed pg-0.18.4
Parsing documentation for pg-0.18.4
Done installing documentation for pg after 4 seconds
1 gem installed
Yet running 'bundle install' again fails. Any suggestions? I've tried uninstalling and reinstalling postgresql with homebrew with no luck
I have got a similar error now on macOS Catalina, but I was not able to successfully run
gem install pg -v '0.18.4'
I found this issue in the puma gem (I know this is another gem) that helped me solve the issue: https://github.com/puma/puma/issues/2304.
There, I found this:
Clang now enables -Werror=implicit-function-declaration by default:
Clang now reports an error when you use a function without an explicit
declaration when building C or Objective-C code for macOS
(-Werror=implicit-function-declaration flag is on). This additional
error detection unifies Clang’s behavior for iOS/tvOS and macOS 64-bit
targets for this diagnostic. (49917738)
And this:
gem install puma:4.3.5 -- --with-cflags="-Wno-error=implicit-function-declaration"
So, I was able to build pg with:
gem install pg -v '0.18.1' -- --with-cflags="-Wno-error=implicit-function-declaration"
The same issue has been faced with all the gems that rely on native extensions such as pg, puma, ffi, etc
I have solved them by passing -- --with-cflags="-Wno-error=implicit-function-declaration"
ex:
gem install pg -v '0.18.4' -- --with-cflags="-Wno-error=implicit-function-declaration"
gem install ffi -v '1.12.2' -- --with-cflags="-Wno-error=implicit-function-declaration"
gem install puma -v '4.3.1' -- --with-cflags="-Wno-error=implicit-function-declaration"
I had to combine Benito's answer and jasonm's answer like below before running bundle (credit to Unixmonkey):
bundle config build.pg '-- --with-cflags="-Wno-error=implicit-function-declaration"'
This isn't an an answer, as such, but it may point you in the right direction... If indeed gem pg has successfully compiled, as you have indicated... Then it maybe that your Ruby project isn't referring to the correct gemset, somehow. As it appears it is attempting to install it again when you bundle install, this should not happen if pg has been compiled and installed in your current gemset. Are you using RVM on your system? Can you also provide more output?
Answer was installing Postgress.app and running
bundle config build.pg --with-pg-config=[Path to pg_config] before bundling
this worked for me on sierra:
gem install pg -v '0.18.3' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config

With Ruby On Rails 4.2.5.1 I can gem install therubyracer but bundle fails on OS X 10.11.1

Using rbenv for a Ruby 2.3.0 environment on OS X 10.11.1 I am unable to get therubyracer Gem to install when using 'bundle'.
This is successful:
> gem install therubyracer
Building native extensions. This could take a while...
Successfully installed therubyracer-0.12.2
Parsing documentation for therubyracer-0.12.2
Done installing documentation for therubyracer after 0 seconds
1 gem installed
In my Gemfile:
gem 'therubyracer', '0.12.2', platforms: :ruby
This fails:
> bundle
Installing therubyracer 0.12.2 (was 0.12.1) with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/jsidlosky/code/sentons/websocket-rails-demo/.bundle/gems/therubyracer-0.12.2/ext/v8
/Users/jsidlosky/.rbenv/versions/2.3.0/bin/ruby -r ./siteconf20160215-9105-1s1s0pv.rb 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.
....
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/jsidlosky/code/sentons/websocket-rails-demo/.bundle/extensions/x86_64-darwin-15/2.3.0-static/therubyracer-0.12.2/mkmf.log
The mkmf.log file's error is:
conftest.c:3:10: fatal error: 'v8.h' file not found
Some things I've tried:
From: How to install therubyracer gem on 10.10 Yosemite?
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.13.gem
From: Bundle install tries to use cache file
Adding to ~/.bundle/config
BUNDLE_PATH: .bundle
BUNDLE_DISABLE_SHARED_GEMS: "1"
I also tried this:
bundle config build.libv8 --with-system-v8
I've now spent well over 5 hours trying other random ideas from various StackOverflow questions and other sites. So far, nothing gets me a working therubyracer inside "bundle" even though "gem install therubyracer" works just perfectly.
I will be very grateful for any pointers or solutions.
It appears from the comment from: github.com/cowboyd/therubyracer/issues/359
"I wasn't able to get any of the above solutions to work (or rather, everything I could get to work would have required the rest of my team to rebundle). After switching from rbenv to RVM, however, bundle install ran without a hitch."
I tried switching from rbenv to RVM and it worked perfectly. I can now 'bundle' and therubyracer gem installs perfectly.

libv8 (3.11.8.17) bundle install error on Mac

I upgraded ruby to 1.9.3, and now I can't get my server to start. When I run bundle install, it says
An error occurred while installing libv8 (3.11.8.17), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.11.8.17'` succeeds before bundling.
When I try to install that gem, it says
ERROR: Error installing libv8:
ERROR: Failed to build gem native extension.
/Users/Erica/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
creating Makefile
Compiling v8 for x64
Using python 2.7.1
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Using compiler: g++
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
I'm an HTML/CSS coder, not really a Ruby developer, so any thoughts are really appreciated.
I resolved this issue by using the following command:
gem install libv8 -v 3.11.8.17 -- --with-system-v8
It works with RVM on Mavericks.
https://stackoverflow.com/a/19667419/763744
Try reinstalling v8 in homebrew:
gem uninstall libv8
brew install v8
gem install libv8
Do:
gem install rmagick -v '2.13.2'
gem install libv8 -v 3.11.8.17 -- --with-system-v8
I encountered this problem a few times already, first thing I'd try is to (re)install command line tools. Normally should work.
Another attempt that succeeded once was uninstalling libv8, and then installing it again. It takes ages...
This simple solution worked for me:
$ gem uninstall libv8 # select "All Versions" if prompted
$ gem install libv8
I had this same problem when I upgraded from OSX Mountain Lion to OSX Mavericks.
Upgrading from ruby-1.8.7-p354 to ruby-1.8.7-375 did the trick for me.
libv8 (3.16.14.3-x86_64-darwin-13) and the therubyracer (0.12.0) gems installed without problem.
assuming you use rbenv:
rbenv versions
system
* 1.8.7-p354
2.0.0-rc2
rbenv uninstall 1.8.7-p354
rbenv install 1.8.7-p375
rbenv versions
system
* 1.8.7-p375
2.0.0-rc2
bundle install

bundle install issue with libv8 and rails

I'm having issues with the libv8 gem with ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]. gem install libv8 works fine and I have
gem 'therubyracer'
in my Gemfile and this has a dependency on libv8 which is installed when I do a bundle install:
$ bundle exec gem list
*** LOCAL GEMS ***
actionmailer (3.1.3)
actionpack (3.1.3)
...
libv8 (3.3.10.4 x86_64-darwin-10)
...
but when I run:
$ rails s
Could not find libv8-3.3.10.4 in any of the sources
Run `bundle install` to install missing gems.
it can't find libv8 - is this is a 32/64 bit issue? If so, how do I solve it?
I suspect this was because I had a 32/64 bit mismatch.
I solved this with the following:
$ irb
ruby-1.9.3-p0 :001 > `gem list`.each_line {|line| `sudo env ARCHFLAGS="-arch x86_64" gem install #{line.split.first}`
I had a similar problem deploying from an x86 dev box to an x86_64 server (using capistrano)
When I did the deployment, I got the same 'Could not find libv8-3.3.10.4 in any of the sources' message. This is because running 'bundle pack' on an x86 machine only copies the x86 gem into the /vendor/cache directory!
I fixed this by explicitly adding the linux x86_64 gem file to the /vendor/cache directory, so that it would agree with the deployment server architecture. Deployment ran fine after that.
Another solution is to use nodejs instead of therubyracer. You install it on the server using apt-get/yum, so there's no need for your Gemfile to include execjs or therubyracer.
You can actually install that version on Mavericks:
gem install libv8 -v 3.11.8.17 -- --with-system-v8
You can provide whatever libv8 gem version you want to install ..
After this you might facing issue with installing therubyracer then
Update Version of Gemfile to point to the last version like so:
gem "therubyracer", "~> 0.10.2"
and I was able to successfully install the gem.
If you want to manually install the gem, you can use:
gem install therubyracer --version "~> 0.10.2"
Have you tried bundle exec rails s? It's possible that there's a conflict between the gems you have installed on your system and the gems that are required for your project to run.
I resolved this issue by installing nodejs (latest version). What it does is that it installs the libv8 -dev library along with it. Thus rather than installing the gem what you require is the native library.
You can install it directly or install nodejs as well in your system and the above error should be resolved.

Resources