Not able to install Jekyll because of therubyracer error on mac - ruby

I am trying to run Jekyll and I have the following contents in the Gemfile
source "https://rubygems.org"
gem 'jekyll-auth'
gem 'redcarpet'
gem 'jekyll-lunr-js-search'
gem 'rouge'
gem 'jekyll-sitemap'
I am running bundle install for installing the dependencies specified. Everything works fine until it tries to install a gem called therubyracer. Then the process is stopped by throwing the following error:
Installing nokogiri 1.11.3 (x86_64-darwin)
Fetching libv8 3.16.14.19
Installing libv8 3.16.14.19 with native extensions
Fetching ref 2.0.0
Installing ref 2.0.0
Fetching therubyracer 0.12.3
Installing therubyracer 0.12.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/therubyracer-0.12.3/ext/v8
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r
./siteconf20210430-34242-1i9kf2u.rb extconf.rb --with-v8-dir\=/usr/local/opt/v8#3.15
checking for -lpthread... yes
checking for -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
--without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
--with-pthreadlib
--without-pthreadlib
--with-objclib
--without-objclib
--enable-debug
--disable-debug
--with-v8-dir
--with-v8-include
--without-v8-include=${v8-dir}/include
--with-v8-lib
--without-v8-lib=${v8-dir}/lib
/Library/Ruby/Gems/2.6.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:50:in `configure': By using
--with-system-v8, you have chosen to use the version (Libv8::Location::System::NotFoundError)
of V8 found on your system and *not* the one that is bundled with
the libv8 rubygem.
However, your system version of v8 could not be located.
Please make sure your system version of v8 that is compatible
with 3.16.14.19 installed. You may need to use the
--with-v8-dir option if it is installed in a non-standard location
from /Library/Ruby/Gems/2.6.0/gems/libv8-3.16.14.19/lib/libv8.rb:7:in `configure_makefile'
from extconf.rb:32:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/therubyracer-0.12.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/therubyracer-0.12.3 for inspection.
Results logged to
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/therubyracer-0.12.3/gem_make.out
An error occurred while installing therubyracer (0.12.3), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.3' --source 'https://rubygems.org/'` succeeds
before bundling.
In Gemfile:
jekyll-lunr-js-search was resolved to 3.3.0, which depends on
therubyracer
Now for fixing this error, I have tried the following commands as specified in some of the posts
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
But this is again giving the same error. I have tried
bundle config build.libv8 --with-system-v8
bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8#3.15)
But there is no luck. I tried by specifying the brew based path for v8, in the command as follows:
sudo gem install therubyracer -- --with-v8-dir= /usr/local/Cellar/v8#3.15
Even after doing all these, I am stuck with the same error which says our system version of v8 could not be located.
I am trying this on a Mac machine with BigSur 11.2.3 is installed and the Ruby version is ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20] and gem is of version 3.0.3.
It will be of great help if someone can tell me how this error can be fixed and I can install and run Jekyll successfully.

I encountered same problem two years ago. I found that libv8 3.16.14.19 is not compatible with therubyracer 0.12.3 and wrote a post to record my solution.
Try the following steps:
Clean up your system
gem uninstall -a libv8
gem uninstall -a therubyracer
Install libv8 with specific version before installing therubyracer
gem install libv8 -v '3.16.14.15'
Install therubyracer
gem install therubyracer -v '0.12.3'
Update libv8 to the version specified in your gemfile
bundle
There may still have problem in macOS BigSur 11.2.
If it raises fatal error: 'climits' file not found in Step 2, try this:
gem install libv8 -v '3.16.14.15' -- --with-system-v8
If it raises errors in Step 3, try this:
brew install v8-315
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8#3.15

Related

An error occurred while installing "gem" and Bundler cannot continue. Mac OS - big sur

This error happened to me before with nio4r gem when I upgraded to Catalina and #dmitry barskov answered it. A similar issue is happening now after big sur upgrade with json, oj and therubyracer (tried using the solution from nio4r, but no luck). When I run gem list I see the gems installed but bundle install fails. So I tried bundle update json oj therubyracer. it works for json and oj but for therubyracer, it throws errors.
therubyracer error -->
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/me/.gem/gems/therubyracer-0.12.2/ext/v8
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r
./siteconf20210106-9670-edtaxk.rb extconf.rb --with-v8-dir\=/usr/local/opt/v8
checking for -lpthread... yes
checking for -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
--without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
--with-pthreadlib
--without-pthreadlib
--with-objclib
--without-objclib
--enable-debug
--disable-debug
--with-v8-dir
--with-v8-include
--without-v8-include=${v8-dir}/include
--with-v8-lib
--without-v8-lib=${v8-dir}/lib
/Users/me/.gem/gems/libv8-3.16.14.19/ext/libv8/location.rb:50:in `configure': By using --with-system-v8, you have chosen to use the version
(Libv8::Location::System::NotFoundError)
of V8 found on your system and *not* the one that is bundled with
the libv8 rubygem.
However, your system version of v8 could not be located.
Please make sure your system version of v8 that is compatible
with 3.16.14.19 installed.
json error -->
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r
./siteconf20210106-29155-126itgi.rb extconf.rb
creating Makefile
current directory: /Users/me/.gem/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR=" clean
current directory: /Users/me/.gem/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
generator.c:861:25: error: use of undeclared identifier 'rb_cFixnum'
} else if (klass == rb_cFixnum) {
^
generator.c:863:25: error: use of undeclared identifier 'rb_cBignum'
} else if (klass == rb_cBignum) {
^
2 errors generated.
make: *** [generator.o] Error 1
make failed, exit code 2
*** LOCAL GEMS ***
bigdecimal (1.2.8)
bundler (1.17.3)
json (1.8.3)
libv8 (3.16.14.17)
oj (2.15.0)
rake (10.4.2)
ref (2.0.0)
therubyracer (0.12.3)
checking for v8.h... no I understand that this maybe an issue, so here's what I've tried to fix it, unsuccessfully ->
brew install v8-315
gem uninstall -a libv8
bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8#3.15)
gem install libv8 -v '3.16.14.17' — —with-system-v8
gem uninstall -a therubyracer
bundle config build.libv8 --with-system-v8
gem install therubyracer -v '0.12.2' -- --with-v8-dir=$(brew --prefix v8#3.15)
When I do bundle update, it gets stuck in resolving dependencies.... I kept it running for 12 hours before I gave up.
When I delete my gemfile.lock, and run bundle install, it gets stuck in resolving dependencies... again.
I'm using ruby v 2.3.1
bundler version 1.17.3
One thing I noticed was the path /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby shows 2.6.0 but I'm using 2.3.1 (confirmed by running rbenv local and ruby -v)
If any other information is needed, please tell me. Any help will be much appreciated.
I ended up deleting the project folder and clone a new one. Removed all gems, reinstalled rbenv like #taylorthurlow pointed out.
Things worked, bundle install was green.

Trouble with gem installations

I am in a coding bootcamp and I have encountered an error in which I am having a hard time fixing. I currently in an exercise where I am learning how to create dynamic routes. Every time I run my server I am getting errors when I go to my routes and it states that:
Could not find nokogiri-1.8.2 in any of the sources
Run `bundle install` to install missing gems.
I tried to bundle install after adding nokogiri to my gemfile but all I get is this error below. I need some help cause I don't know what is going on and I am a total noob in regards to this stuff.
Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.5
Ignoring websocket-driver-0.7.0 because its extensions are not built. Try: gem pristine websocket-driver --version 0.7.0
Fetching gem metadata from http://rubygems.org/........
Using rake 12.3.0
Using concurrent-ruby 1.0.5
Using i18n 0.9.5
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.1.5
Using activemodel 5.1.5
Using arel 8.0.0
Using activerecord 5.1.5
Using public_suffix 3.0.2
Using addressable 2.5.2
Using bundler 1.16.6
Using mini_mime 1.0.0
Using mini_portile2 2.3.0
Fetching nokogiri 1.8.2
Installing nokogiri 1.8.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/Users/kenkuts/.rvm/gems/ruby-2.5.0/gems/nokogiri-1.8.2/ext/nokogiri
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r
./siteconf20181215-54662-1izm05e.rb extconf.rb --use-system-libraries
Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine
unf_ext --version 0.0.7.5
Ignoring websocket-driver-0.7.0 because its extensions are not built. Try: gem
pristine websocket-driver --version 0.7.0
checking if the C compiler accepts ... *** 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
--without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/$(RUBY_BASE_NAME)
--help
--clean
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:456:in
`try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:571:in
`block in try_compile'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:522:in
`with_werror'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:571:in
`try_compile'
from extconf.rb:138:in `nokogiri_try_compile'
from extconf.rb:162:in `block in add_cflags'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:629:in
`with_cflags'
from extconf.rb:161:in `add_cflags'
from extconf.rb:410:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can
be found here:
/Users/kenkuts/.rvm/gems/ruby-2.5.0/extensions/universal-darwin-18/2.3.0/nokogiri-1.8.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in
/Users/kenkuts/.rvm/gems/ruby-2.5.0/gems/nokogiri-1.8.2 for inspection.
Results logged to
/Users/kenkuts/.rvm/gems/ruby-2.5.0/extensions/universal-darwin-18/2.3.0/nokogiri-1.8.2/gem_make.out
An error occurred while installing nokogiri (1.8.2), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.8.2' --source 'http://rubygems.org/'`
succeeds before bundling.
In Gemfile:
capybara was resolved to 2.18.0, which depends on
xpath was resolved to 3.0.0, which depends on
nokogiri
You may need to download Xcode from the App Store, and run the commands
xcode-select --install
sudo xcodebuild -license`
The nokogiri install instructions mention this:
https://www.nokogiri.org/tutorials/installing_nokogiri.html#install_with_included_libraries__recommended_
This isn't an "answer" as much as a set of (hopefully) helpful things too long for a comment.
Sandbox your gems
I always run bundler in the following way now, so that one project's dependencies have no impact on the gems I use system wide or on other projects:
bundle install --binstubs --path=vendor.noindex
That will put all executables in PROJECT_DIR/bin and all gems in PROJECT_DIR/vendor.noindex. The "noindex" bit stops Spotlight from indexing the gems. To run rspec would now be:
bin/rspec
To start from a clean slate I run:
rm -rf .bundle bin Gemfile.lock vendor.noindex
Note: Always be careful using an rm -rf!!!!
Installing and finding dependencies
The last time I installed Nokogiri using the gem install command it looked like this:
gem install nokogiri -- \
--use-system-libraries \
--with-xml2-include=/opt/pkg/include/libxml2 \
--with-xml2-lib=/opt/pkg/lib \
--with-xslt-include=/opt/pkg/include/libxslt \
--with-xslt-lib=/opt/pkg/lib
As other commenters have noticed, this shows that you need XCode installed (always worth checking for updates) and that I've used libraries installed by another package manager (I've used pkgrsc above though you could use Macports or Homebrew and maybe some others).
To find the libs you need to link to try running:
find `/usr` -name libxml2 -type d 2> >(grep -v 'Permission denied' >&2)
Or change the /usr to /opt if you're installing there via pkgsrc/Macports/Fink etc. You may need to put a sudo in front depending on the permissions.
There's also the locate command, e.g.
locate libxml2
Which will bring up lots of stuff.

Bundle install fails to install libxml-ruby

I'm a new to Ruby world and I need to clone an existing project.
The instructions are:
source .env.development
bundle install
But it fails with:
Using libv8 3.16.14.15
Fetching libxml-ruby 2.9.0
Installing libxml-ruby 2.9.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/vlad/.rvm/gems/ruby-2.3.1/gems/libxml-ruby-2.9.0/ext/libxml
/Users/vlad/.rvm/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20181109-46682-fvgifh.rb extconf.rb --use-system-libraries
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... 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/vlad/.rvm/rubies/ruby-2.3.1/bin/$(RUBY_BASE_NAME)
--with-xml2-config
--without-xml2-config
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
extconf failure: need libxml2.
Install the library or try one of the following options to extconf.rb:
--with-xml2-config=/path/to/xml2-config
--with-xml2-dir=/path/to/libxml2
--with-xml2-lib=/path/to/libxml2/lib
--with-xml2-include=/path/to/libxml2/include
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/vlad/.rvm/gems/ruby-2.3.1/extensions/x86_64-darwin-18/2.3.0/libxml-ruby-2.9.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/vlad/.rvm/gems/ruby-2.3.1/gems/libxml-ruby-2.9.0 for inspection.
Results logged to /Users/vlad/.rvm/gems/ruby-2.3.1/extensions/x86_64-darwin-18/2.3.0/libxml-ruby-2.9.0/gem_make.out
An error occurred while installing libxml-ruby (2.9.0), and Bundler cannot continue.
Make sure that `gem install libxml-ruby -v '2.9.0'` succeeds before bundling.
In Gemfile:
upnxt_community_lib_common was resolved to 1.7.49, which depends on
upnxt_processing_lib_document was resolved to 2.0.0, which depends on
libxml-
If I want to execute the command that is suggested "gem install libxml-ruby -v '2.9.0'" I get the same error.
Operating System: MacOS Mojave, version 10.14.
Ruby version needed for the project: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin18]
I also tried this but it didn't helped.
Thanks in advance for any help!
These steps worked for me (source)
brew install libxml2
bundle config --global build.libxml-ruby --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config"
then bundle install worked as expected
I manage to fix this with the help of a colleague, if anybody else encounter this problem:
gem install libxml-ruby -v '2.9.0' -- --use-system-libraries --with-xml2-dir=/usr/local/Cellar/libxml2/2.9.8/include/libxml2/libxml/ --with-xml2-config=/usr/bin/xml2-config
Replace '2.9.0' with the libxml version that you need!
It solved for me in mac by running
gem install libxml-ruby -v '3.0.0' -- --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xml2-include=/usr/local/opt/libxml2/include
Just happened today.
$ brew link --force libxml2
Warning: Refusing to link macOS-provided software: libxml2
...
At first, I wasn't aware that there's a warning and it doesn't work anymore.
Then found this workaround and it worked for me.
bundle config build.libxml-ruby --use-system-libraries=true --with-xml2-include=/usr/local/opt/libxml2/include/libxml2/
I've encountered many tips while googling around today. I've tried to compile them into a logical order of some things to try:
Installing/debugging libxml on mac for ruby/rails.
There's a lot on this page already. But just to point out a few extra things I've gathered from elsewhere.
To me it seems more sensible to try to get a working bundle config command than to bypass this with a gem install command. So use skplunkerin's answer, or...
The following will configure it to use the system libxml headers:
bundle config --global build.libxml-ruby --with-xml2-include=`xcrun --show-sdk-path`/usr/include/libxml2
bundle install
...which worked better for me today. The libxml-ruby gem build was having issues with the latest homebrew installed libxml vs an older system libxml.

Your Gemfile.lock is corrupt. The following gems are missing from the DEPENDENCIES section:

I am installing one app and I was in this step that I should run bundle install and I get this error
enter code here➜ mavatar git:(master) ✗ bundle install
Fetching gem metadata from http://rubygems.org/
Fetching version metadata from http://rubygems.org/
Fetching dependency metadata from http://rubygems.org/
Using rake 0.9.2
Using multi_json 1.8.2
Using bcrypt-ruby 3.0.1
Using builder 3.0.4
Using i18n 0.6.5
Using erubis 2.7.0
Using rack 1.3.6
Using hike 1.2.1
Using tilt 1.3.3
Installing nokogiri 1.5.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /home/farbodi/.rvm/gems/ruby-2.3.0-
dev/gems/nokogiri-1.5.0/ext/nokogiri
/home/farbodi/.rvm/rubies/ruby-2.3.0-dev/bin/ruby -r
./siteconf20160806-31805-mdcnrl.rb extconf.rb
*** 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
--without-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=/home/farbodi/.rvm/rubies/ruby-2.3.0-dev/bin/$(RUBY_BASE_NAME)
extconf.rb:10:in `<main>': uninitialized constant Config (NameError)
Did you mean? RbConfig
CONFIG
extconf failed, exit code 1
Gem files will remain installed in /home/farbodi/.rvm/gems/ruby-
2.3.0-dev/gems/nokogiri-1.5.0 for inspection.
Results logged to /home/farbodi/.rvm/gems/ruby-2.3.0-
dev/extensions/x86_64-linux/2.3.0/nokogiri-1.5.0/gem_make.out
Your Gemfile.lock is corrupt. The following gems are missing from the
DEPENDENCIES section: 'archive-tar-minitar' 'hoe' 'rcov'
So I tried to run this : gem update
gem install hoe
gem install rcov
gem install archive-tar-minitar
gem install nokogiri -v 1.5.0 which gives me ERROR: Failed to build gem native extension. error
I also installed bundle older version, I can pass this step but I get same problem in somewhere else.
I also used rvm and my ruby version is ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux] , And Bundler version 1.12.5
I am new to ruby and gem and bundle I am all confused and I don't know how to start to learn what is going on and how to solve the errors.
You need to install some system packages.
If you are using redhat based, install libxml2 and libxslt and zlib-devel
and if you are using debian based, install zlib1g-dev and liblzma-dev packages

How to install therubyracer gem on 10.10 Yosemite?

I don't manage to install therubyracer gem on Yosemite 10.10.
Here is the log:
11:53 $ gem install libv8 -v '3.16.14.3' -- --with-system-v8
Building native extensions with: '--with-system-v8'
This could take a while...
Successfully installed libv8-3.16.14.3
Parsing documentation for libv8-3.16.14.3
Installing ri documentation for libv8-3.16.14.3
Done installing documentation for libv8 after 0 seconds
1 gem installed
02:05 $ gem install therubyracer -v '0.12.1' -- --with-system-v8
Building native extensions with: '--with-system-v8'
This could take a while...
ERROR: Error installing therubyracer:
ERROR: Failed to build gem native extension.
/usr/local/var/rbenv/versions/2.1.2/bin/ruby extconf.rb --with-system-v8
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
--without-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=/usr/local/var/rbenv/versions/2.1.2/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
/usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/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 bundle 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 /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/libv8-3.16.14.3/lib/libv8.rb:7:in `configure_makefile'
from extconf.rb:32:in `'
extconf failed, exit code 1
Gem files will remain installed in /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1 for inspection.
Results logged to /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/therubyracer-0.12.1/gem_make.out
gem uninstall libv8
brew install v8
gem install therubyracer
gem install libv8 -v '3.16.14.3' -- --with-system-v8
this is the only way it worked for me on 10.10 (ruby 2.1.2)
Or try gem install libv8 -v 'XX.XX.XX' -- --with-system-v8 adding the version of the gem :)
UPDATE for Mac OS Catalina:
brew tap homebrew/versions
brew install v8#3.15
brew link --force v8#3.15
gem install libv8 -v 'XX.XX.XX' -- --with-system-v8
gem install therubyracer
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.3-x86_64-darwin-12.gem #note that libv8 version may change, so tab through files in pkg/, also remember to use the one with version specified
then just bundle your project gems
this is the only way it worked for me on 10.10 (ruby 2.1.2)
None of the answers work for me this time. I have too use this:
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
Seen on the rubyracer Github issues.
Hope it helps someone else.
Maybe it will be useful for someone but I had problems installing therubyracer (because of the problems with libv8) the solution was to uninstall all the libv8 that I had installed. Install therubyracer
$ gem uninstall libv8
$ gem install therubyracer -v '0.12.0'
Fetching: libv8-3.16.14.7-x86_64-darwin-14.gem ( 57%)
Fetching: libv8-3.16.14.7-x86_64-darwin-14.gem (100%)
Successfully installed libv8-3.16.14.7-x86_64-darwin-14
Building native extensions. This could take a while...
Successfully installed therubyracer-0.12.0
2 gems installed
I hope this helps someone.
It seems like this has been fixed upstream. What worked for me and #aurels and #Mike Causer and #Juanda was:
bundle update libv8
This worked for me very well on my Yosemite and Ruby 2.1.5 (Ruby through RVM)
gem install libv8 -v '3.16.14.3' -- --with-system-v8
Earlier it was giving me error Gem::Ext::BuildError: ERROR: Failed to build gem native extension. for libv8 gem version 3.16.14.3
Only this works for me in my Yosemite, Ruby 2.1.2:
gem install libv8 -v '3.16.14.3' -- --with-system-v8
brew link --overwrite v8-315 --force
gem install therubyracer -v '0.12.2' -- --with-system-v8
I was able to proceed with ruby racer after rm Gemfile.lock
beforehand:
I installed v8 via brew install v8, and then did gem install libv8 -v '3.16.14.3' -- --with-system-v8
and I am running 10.10 Yosemite
They have corrected this issue in the most recent version of libv8. See: https://github.com/cowboyd/libv8/issues/123
You should install from the github repo, in rails I added a line to my gemfile like this gem "libv8", git: "git://github.com/cowboyd/libv8.git", submodules: true
EDIT:
This apparently only solves some of the problem. I installed the new version of libv8, but now the rubyracer is still looking for the other one I think? Still looking into it.
I had the same issue on Yosemite. My solution is similar to what appears above.
Use gem uninstall libv8 to remove anything that might be installed.
Leave therubyracer in your Gemfile, but remove any explicit reference to libv8.
Run bundle install.
libv8 then installed fine as a dependency.
Updated answer for 2018.
I'm on High Sierra, on Homebrew 1.6.1
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#3.15/
Is what worked for me.
Credit goes to #coding-addicted for his original answer.
After hours of trying simply upgrading ruby worked:
brew install ruby
and then adding the following to gem file:
gem 'libv8'
gem 'therubyracer'
A heads up to anyone that might have been having my issue: I ended up uninstalling my ruby version in RVM and then reinstalling it. That seemed to use the correct dependancies in the latest version of xcode tools for compiling ruby.
rvm list
rvm uninstall ruby-x.x.x
rvm install ruby-x.x.x
I did the following
gem install therubyracer
which now installs therubyracer 0.12.1 which installs the dependency libv8 (3.16.14.7 x86_64-darwin-14) which installed with no errors.
I did this using ruby 2.1.5 which I installed via:
CC=/usr/bin/gcc rbenv install 2.1.5
which I did after running brew upgrade ruby-builds.
After installing ruby 2.1.5, I also ran
gem upgrade --system
to get rubygems-update 2.4.5
this happens due to some conflicts with the libv8 as well, although you can just assign a version to the rubyracer and it will be installed:
change the following in the gemfile:
gem 'therubyracer', '~> 0.12.1'
and do bundle install
What worked for me, based on the following comment,
https://github.com/cowboyd/therubyracer/issues/304#issuecomment-62046085
was to remove Gemfile.lock and then run bundle install
This solution worked for me following Jakub Troszok's solution above with just a minor change
gem uninstall libv8
gem install therubyracer -v '0.12.1'
Fetching: libv8-3.16.14.19-x86_64-darwin-18.gem (100%)
Successfully installed libv8-3.16.14.19-x86_64-darwin-18
Building native extensions. This could take a while...
Successfully installed therubyracer-0.12.1
Parsing documentation for libv8-3.16.14.19-x86_64-darwin-18
Installing ri documentation for libv8-3.16.14.19-x86_64-darwin-18
Parsing documentation for therubyracer-0.12.1
Installing ri documentation for therubyracer-0.12.1
Done installing documentation for libv8, therubyracer after 0 seconds
2 gems installed
gem install libv8 -v '3.16.14.17' -- --with-system-v8 (if the libv8 version required for your project is different from the one installed by rubyracer)
bundle install
Using homebrew's directory of v8 for --with-v8-dir=/usr/local/Cellar/v8#3.15/3.15.11.18_1, instead of /usr/local/opt/v8-315, is what worked for me, in coding addicted's answer.
This is visible in the Summary of the brew install command, brew install v8-315.

Resources