therubyracer - Gem::Ext::BuildError: ERROR: Failed to build gem native extension

This steps worked for me.

OS: Maverick Ruby: 2.1.1

gem uninstall libv8
gem install therubyracer -v '0.11.3'
gem install libv8 -v '3.11.8.13' -- --with-system-v8

For those facing this problem in OS X El Capitan, this solution from a therubyracer issue thread was what finally worked for me:

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

I had also run brew install gcc prior, but I'm not sure whether this was in fact necessary.


Try first uninstalling libv8 gem, then install rubyracer, and then libv8

gem uninstall libv8
gem install therubyracer
gem install libv8 -- --with-system-v8

Tertom's solution posted on github solved it for me, after having tried all other solutions proposed on the respective github issue and here.
I had the exact same system configuration.
This is on el capitan, so not an exact answer to the question, but people might find this info helpful.

I'm citing it here for visibility:

Solved the same problem

  • MacOS 10.11.2
  • ruby 1.9.3
  • libv8 3.16.14.13
  • therubyracer 0.12.2

--

brew tap homebrew/versions  
brew install v8-315  
brew link --force v8-315  
bundle install  
brew unlink v8-315

If you also cannot install libv8,

gem install libv8 --with-system-v8

or

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

For all of you out there using macOS 10.15, brew has has changed so you will need to do these commands.

brew install [email protected]
gem install libv8 -v 'YOUR_VERSION' -- --with-system-v8
gem install therubyracer -v 'YOUR_VERSION' -- --with-v8-dir=/usr/local/opt/[email protected]
bundle install