therubyracer install error. I tried all other SO s

2019-07-28 04:40发布

问题:

I think this is a common problem of installing therubyracer gem in Rails. It is a dependency for the twitter-bootstrap-rails gem.

I have tried solution such as this: `gem install therubyracer` fails on Mac OS X Lion

Here is the portion of my gem file that's relavant:

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'

  gem 'twitter-bootstrap-rails'
end

And here is the error I got when running bundle install:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/lionel_lei/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for main() in -lobjc... yes
creating Makefile

make
compiling rr.cpp
make: clang++: No such file or directory
make: *** [rr.o] Error 1


Gem files will remain installed in /Users/lionel_lei/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.10.2 for inspection.
Results logged to /Users/lionel_lei/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.10.2/ext/v8/gem_make.out
An error occured while installing therubyracer (0.10.2), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.10.2'` succeeds before bundling.

My system environment is: Rails 3.2.6 ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.1] Mac OSX 10.7.4 (lion) Xcode 4.5

  • I've been pulling my hair out. I am new to ruby/rails, heck I am new to coding in general so the error message doesn't make much sense to me. I am guessing it's some kind of compiler issue.

Thanks for your help.

回答1:

I experienced the same problem, which I resolved by installing libv8 (gem install libv8), then installing therubyracer. You will need to have Apple XCode installed first (install from the App Store) as this includes the c compiler that you will need to build libv8.

EDIT: Once you have installed XCode, if you are using the latest version you will need to manually install the "command line tools" to get the c compiler, you can find this in XCode --> preferences --> downloads --> install command line tools.