Search code examples
ubunturubygemsbundlerubuntu-20.04

Cannot install therubyracer on Ubuntu 20.04


Firstly in order to install therubyracer, I was supposed to install using the instructions below given by a Mac user.

# !!! Below will not work !!!
linux brew install v8-315 # Segmentation Fault (core dumped) error
bundle config --local build.libv8 --with-system-v8

However running the above will cause Segementation error so I decided to run the below.

# This works
gem install libv8 # This works
bundle set config --local build.libv8 --with-system-v8

Then I tried:

bundle config set --local build.therubyracer --with-v8-dir=/var/lib/gems/2.7.0/gems/libv8-3.16.14.19 --with-system-v8 # Where libv8 gem is installed

But this does not work when I run:

bundle install --path vendor/bundle

The error in bundle install is:

home/xxxx/Desktop/dsp-manage/vendor/bundle/ruby/2.7.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 /home/xxxx/Desktop/dsp-manage/vendor/bundle/ruby/2.7.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:

  /home/xxxx/Desktop/dsp-manage/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/therubyracer-0.12.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/xxxx/Desktop/dsp-manage/vendor/bundle/ruby/2.7.0/gems/therubyracer-0.12.3 for inspection.
Results logged to /home/xxxx/Desktop/dsp-manage/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.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:
  therubyracer

The error in gem_make.out is:

current directory: /home/xxxx/Desktop/dsp-manage/vendor/bundle/ruby/2.7.0/gems/therubyracer-0.12.3/ext/v8
/usr/bin/ruby2.7 -I /usr/lib/ruby/2.7.0 -r ./siteconf20210326-38637-x0u0s3.rb extconf.rb --with-v8-dir\=/var/lib/gems/2.7.0/gems/libv8-3.16.14.19 --with-system-v8
checking for -lpthread... 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/bin/$(RUBY_BASE_NAME)2.7
    --with-pthread-dir
    --without-pthread-dir
    --with-pthread-include
    --without-pthread-include=${pthread-dir}/include
    --with-pthread-lib
    --without-pthread-lib=${pthread-dir}/lib
    --with-pthreadlib
    --without-pthreadlib
    --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
/home/xxxx/Desktop/dsp-manage/vendor/bundle/ruby/2.7.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 /home/xxxx/Desktop/dsp-manage/vendor/bundle/ruby/2.7.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:

  /home/xxxx/Desktop/dsp-manage/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/therubyracer-0.12.3/mkmf.log

extconf failed, exit code 1

Solution

  • For linux mint on Ubuntu 20 based. and linux mint 21

    $ gem uninstall therubyracer 
    $ gem uninstall libv8
    
    $ gem install therubyracer -v '0.12.3' -- --with-system-v8
    $ gem install libv8 -v '3.16.14.19' -- --with-system-v8
    $ bundle config build.libv8 --with-system-v8
    
    $ bundle
    

    it worked for me.