Not able to install Jekyll because of therubyracer error on mac

422 views Asked by At

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/[email protected]
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 [email protected])

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/[email protected]

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.

1

There are 1 answers

4
khiav reoy On BEST ANSWER

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:

  1. Clean up your system
gem uninstall -a libv8
gem uninstall -a therubyracer
  1. Install libv8 with specific version before installing therubyracer
gem install libv8 -v '3.16.14.15'
  1. Install therubyracer
gem install therubyracer -v '0.12.3'
  1. 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/[email protected]