ChatGPT解决这个技术问题 Extra ChatGPT

Installing libv8 gem on OS X 10.9+

I'm trying to install libv8 3.16.14.3 but getting an error on OSX Mavericks using latest stable rvm and ruby-1.9.3-p125.

This is the output of running the command 'gem install libv8':

~/src(branch:master) » gem install libv8
Fetching: libv8-3.16.14.3.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
  ERROR: Failed to build gem native extension.

    /Users/me/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
creating Makefile
Compiling v8 for x64
Using python 2.7.5
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Using compiler: g++
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
libtool: unrecognized option `-static'
libtool: Try `libtool --help' for more information.
make[1]: *** [/Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/libpreparser_lib.a] Error 1
make: *** [x64.release] Error 2
/Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:36:in `block in verify_installation!': libv8 did not install properly, expected binary v8 archive '/Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a'to exist, but it was not found (Libv8::Location::Vendor::ArchiveNotFound)
  from /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:35:in `each'
  from /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:35:in `verify_installation!'
  from /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:26:in `install!'
  from extconf.rb:7:in `<main>'
GYP_GENERATORS=make \
  build/gyp/gyp --generator-output="out" build/all.gyp \
                -Ibuild/standalone.gypi --depth=. \
                -Dv8_target_arch=x64 \
                -S.x64  -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/atomicops_internals_x86_gcc.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum-dtoa.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/cached-powers.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/conversions.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/diy-fp.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/dtoa.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/fast-dtoa.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/fixed-dtoa.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/once.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/preparse-data.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/preparser.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/preparser-api.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/scanner.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/strtod.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/token.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/unicode.o
  CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/utils.o
  LIBTOOL-STATIC /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/libpreparser_lib.a


Gem files will remain installed in /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3 for inspection.
Results logged to /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/gem_make.out
Be aware that Rails projects do not need therubyracer just to pre-compile assets as long as execjs can find NodeJS in your path.

C
Community

This is due to the fact that OS X 10.9+ is using version 4.8 of GCC. This is not supported officially in older versions of libv8 as mentioned in the pull request (https://github.com/cowboyd/libv8/pull/95). Please try bumping up the version of libv8 in your Gemfile (or) a bundle update should suffice. Hope this helps.

From the libv8 README

Bring your own V8

Because libv8 is the interface for the V8 engine used by therubyracer, you may need to use libv8, even if you have V8 installed already. If you wish to use your own V8 installation, rather than have it built for you, use the --with-system-v8 option.

Using RubyGems:

gem install libv8 [-v YOUR_VERSION] -- --with-system-v8

Using Bundler (in your Gemfile):

bundle config build.libv8 --with-system-v8

Please note that if you intend to run your own V8, you must install both V8 and its headers (found in libv8-dev for Debian distros).

Bring your own compiler

You can specify a compiler of your choice by either setting the CXX environment variable before compilation, or by adding the --with-cxx= option to the bundle configuration:

bundle config build.libv8 --with-cxx=clang++

Edit:

If this issue is brought on by therubyracer, try the following as suggested by rider_on_rails here:

gem uninstall libv8 gem install therubyracer -v YOUR_RUBY_RACER_VERSION gem install libv8 -v YOUR_VERSION -- --with-system-v8


Unfortunately I can't change the version of libv8 in the project I'm working on. I'll be downgrading to OSX 10.8 for now!
--with-system-v8 FTW!
Thanks! bundle config build.libv8 --with-system-v8 helps!
bundle update bailed me out of the realm of numbness and apple-upgrade-inflicted-miseries
In case someone gets the following problem with therubyracer gem after solving this one: stackoverflow.com/questions/23536893/…
O
Oliver Shaw

You can actually install that version on Mavericks:

gem install libv8 -v 3.11.8.17 -- --with-system-v8

I can confirm this works with rbenv and ruby 1.9.3p448


Same for me - os x 10.9, rbenv and ruby-2.0.0-p247
Worked on 1.8.7 for an old project :)
Why does this work? Which part of the command is --with-system-v8 modifying, and what is it doing?
As per the instructions here github.com/cowboyd/libv8 libv8 allows you to use a pre-existing version of the V8 engine (en.wikipedia.org/wiki/V8_(JavaScript_engine)) rather than compiling one yourself. It's the compilation that is an issue in mavericks as the C++ compilers have changed. You can compile libV8 yourself using the instructions here (stackoverflow.com/a/19668162/2012130)
works with rbenv and ruby 2.1.1 - gem install libv8 -- --with-system-v8
E
Evgeniya Manolova

El Capitan Solution for me:

$ brew install v8
$ gem install libv8 -v REQUIRED_LIBV8_VERSION -- --with-system-v8

Where REQUIRED_LIBV8_VERSION for me was 3.16.14.7, but you need to check which is the one you need in your bundle (this was the one for rails 4.2.5)

You may also need to run the commands above as the superuser (if your gems and system libraries are global)


You shouldn't use sudo for brew install or gem install. This creates permission issues.
@benDangelo, what you say is absolutely correct. Even though the system sometimes might require root privileges for installing software it's a bad practice to use sudo on a general basis. I'll edit my response, thanks.
It works for me! thank you. This was the only working solution.
just installing v8 did the work for me ... then no need to add flags with gem command
P
Peter DeWeese

You can configure bundler instead of having to know each version. @3.15 could be replaced with other versions.

$ brew install v8@3.15
$ bundle config build.libv8 --with-system-v8
$ bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8@3.15)
$ bundle install

Works on macOS Catalina. Thank you!
You're my saviour, I have pretty old application with rubyracer dependency. The only note, brew don't have other v8 versions now, just v8@3.15 and v8
Worked for me on Monterey. Thanks!
L
Lei Wang

My issue is since therubyracer, when update to macOS 10.15 and ruby-2.6.5

And the following works for me:

brew install v8@3.15

gem install libv8 -v 3.16.14.19 -- --with-system-v8

gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8@3.15

This is the only thing that worked for me to get therubyracer working on an old project on Catalina. Thanks.
Thank you., worked for me in Catalina, ruby 2.7.2, rails 5.2.4.
S
Steven Hirlston

When I tried the accepted answer, libv8 would install successfully with gem install libv8, but bundle install would fail on libv8. I think that bundle install was trying to install a different version of libv8. I was able to find a solution that worked for me.

I needed libv8 because therubyracer depends on it. To get it to install, I noted the version that was failing to install in the gem_make.out log for therubyracer. (The path for the gem_make.out log will be in the failure message.) In my case it was 3.16.14.7. (This version will probably change over time, in case you're reading this three years from now.) Then I did this:

gem install libv8 -v 3.16.14.7 -- --with-v8-lib <-- note different flag from accepted answer

which allowed this to work:

gem install therubyracer

which allowed me to complete my bundle install.

This worked for me on OSX Yosemite.


I should note that bundle install broke for me immediately after I upgraded to OSX Yosemite, which is why I had to find this solution.
This works brilliantly on OS X Yosemite while many other answers simply do not work.
Thanks mate. 'therubyracer' finally installed.
S
Stefanos.Ioannou

https://github.com/cowboyd/therubyracer/issues/339

jasonlynes's solution found on that link made the trick for me. anything else didn't work.

brew install homebrew/versions/v8-315
brew link --overwrite v8-315 --force
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -v '0.12.2' -- --with-system-v8

I can't believe why this is still an issue in 2020... Thanks @Stefanos.Ioannou this is the solution that worked for me.
c
chriszo111

I updated to macOS Catalina @ 10.15 and ruby 2.6.5. After a while got libv8 and therubyracer to install again, although I'd recommend not to update macOS yet (I heard ruby should be fine).

First, I had to update XCode

xcode-select --install

I used rbenv to update ruby, and set the ruby version manually in /Users/<username>/.rbenv/version to 2.6.5. Although this shouldn't matter if your project contains a .ruby-version file.

Then I cleaned up any version I installed fro libv8 (usually in /usr/local/opt/): brew uninstall v8, brew uninstall libv8@3.15

brew install v8@3.15

Now, following https://github.com/cowboyd/libv8#do-i-get-a-binary, I installed

gem install libv8 -v '3.16.14.19' -- --with-system-v8

and then could run bundle install without errors.


T
Tom Chapin

None of this helped me... no matter what I did, my gem install of therubyracer kept complaining with this error:

Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Beginning compilation. This will take some time.
Building v8 with env CXX=clang++ LINK=clang++  /usr/local/bin/gmake x64.release ARFLAGS.target=crs werror=no
GYP_GENERATORS=make \
build/gyp/gyp --generator-output="out" build/all.gyp \
              -Ibuild/standalone.gypi --depth=. \
              -Dv8_target_arch=x64 \
              -S.x64 -Dmac_deployment_target=10.15 -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 -Dwerror=''
  File "build/gyp/gyp", line 12
    except ImportError, e:
                      ^
SyntaxError: invalid syntax
gmake: *** [Makefile:268: out/Makefile.x64] Error 1

What ultimately helped me was this other forum I stumbled upon at https://www.bountysource.com/issues/82833405-libv8-fails-to-build-on-catalina-10-15

The final solution that worked for me:

I had to add these lines to my .zshrc file:

export CXX=clang++
export GYPFLAGS=-Dmac_deployment_target=10.15

Then I had to run these commands:

source ~/.zshrc
brew tap homebrew/homebrew-core
brew install v8@3.15
gem uninstall therubyracer
gem uninstall libv8
gem install libv8 -v '3.16.14.19' -- --with-system-v8
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15
bundle install

I hope someone else finds this useful!


C
Community

Try with what I summarized in this question: "gem install therubyracer -v '0.10.2'" on osx mavericks not installing

It worked for me (OS X Mavericks)


n
nelsonenzo

I had this same problem when I upgraded from OSX Mountain Lion to OSX Mavericks. The accepted answer worked for libv8, but not when I went to bundle install therubyracer gem.

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

T
TomFuertes

This worked fine for me:

Try installing this pre-compiled gem:

https://dl.dropboxusercontent.com/u/7919548/gems/libv8/libv8-3.11.8.17-x86_64-darwin-13.gem (sha1:5ce07aaf4085fff5a5e10fe018fd6b22021bef3b)

Or if you prefer to build your own:

  git clone https://github.com/cowboyd/libv8.git
  cd libv8
  git checkout 3.11
  bundle install
  bundle exec rake clean build binary
  gem install pkg/libv8-3.11.8.17-x86_64-darwin-13.gem

Source: https://github.com/cowboyd/libv8/issues/107

Thanks to Felix Bünemann for the fix!


C
Community

I tried a number of solutions outlined in previous answers, but found that running bundle (to install other, missing gems) would attempt to re-compile libv8 (despite having already installed it successfully using --with-system-v8) and thus suffer from the same issue.

Eventually, I found that removing the libv8 gem, fetching the gem file from rubygems, and then manually installing the .gem file with the --with-system-v8 flag worked for me.

i.e.

gem uninstall libv8
gem fetch libv8 -v LIBV8_VERSION
gem install libv8-LIBV_VERSION.gem -- --with-system-v8
bundle

Thanks to Gaurav Agarwal's answer for leading me down the right path!


R
RonanOD

You can try manually compiling and installing the gem via the method mentioned on the libv8 github site.


K
Kishore Mohan

In MAC-Yosemite with RVM environment and ruby-2.1.1 version

gem install libv8 -v 3.16.14.3 -- --with-v8-lib gem install therubyracer

It works with the help of above command, can confirm this.


t
tomascharad

What really worked for me was upgrading ruby to 2.2.0, removing Gemfile.lock and bundling over again.

Worked like a charm!


A
Arian Faurtosh

This is what worked for me.

replace 3.16.14.7 with your version.

bundle install
gem install libv8 -v '3.16.14.7' -- --with-system-v8

bundle install
gem uninstall libv8 -v '3.16.14.7' -- --with-system-v8

brew install homebrew/dupes/apple-gcc42

export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2

bundle install

this forces an older gcc, which would be a band-aid at best and will definitely cause issues down the road.
b
bittterbotter

I have faced a similar problem on El Cap. Here's what I did.

brew tap homebrew/dupes
brew install apple-gcc42

And then,

export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2

Finally,

brew uninstall v8
gem install libv8 -v 3.11.8.17 -- --with-system-v8

h
huwr

I was using a beta version of Xcode for another project and had forgotten. Switch back with xcode-select. Something like:

sudo xcode-select --switch /Applications/Xcode.app/

R
Roberto Capelo

Remove from Gemfile:

gem 'therubyracer', :platforms => :ruby


This sort of defeats the entire purpose of this post.

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now