Fix for "Nokogiri failed to build gem native extension" - ruby

The command on my Mac
$ gem install nokogiri -v '1.7.1'
gives the error
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
I tried using
bundle config build.nokogiri --use-system-libraries
but it didn't help, I get the same error

The fix was to use
xcode-select --install
and accept the GUI prompt that comes up about developer options.
Then the gem install and bundle commands worked.

Related

ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. MacOS

I have no experience with Ruby. When I try to do gem install nokogiri on MacOS I am getting.
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.10.5/ext/nokogiri
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20191105-81089-x3wjwy.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.10.5 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/nokogiri-1.10.5/gem_make.out
Did you try?
gem update --system
xcode-select --install
The following should fix your issue:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
sudo xcodebuild -license accept
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Error installing compass in OSX Yosemite (or Sierra)

Good day
I have a Mac with OSX Yosemite
I'm trying to install the compass with the command:
sudo gem install compass
but I am getting the following error:
Building native extensions. This could take a while...
ERROR: Error installing compass:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20151001-1122-1jqcu8r.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.10 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/ffi-1.9.10/gem_make.out
before attempting to install the package I updated the gem with the command
sudo gem update --system
and the update occurred without errors
You probably need to install the command line developer tools first.
xcode-select --install
Then try sudo gem install compass again

Trying to install pg gem fails during ruby project build

I'm attempting to build a ruby project which uses postgres running locally. Build fails on the pg gem install. I get this error
$ gem install pg -v '0.12.2'
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/path/to/.rvm/rubies/ruby-1.9.3-p545/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
so... I pass the pg_config path, and get a different error:
$ gem install pg --with-pg-config=/usr/pgsql-9.2/bin/pg_config -v '0.12.2'
ERROR: While executing gem ... (OptionParser::InvalidOption)
invalid option: --with-pg-config=/usr/pgsql-9.2/bin/pg_config
Very confused.
Make sure you have libpq-dev package installed. If you don't, install it and try installing pg again without the --with-pg-config parameter.
In regards to the --with-pg-config parameter:
When passing parameters to the gem you're installing you must use two dashes before the two dashes from the option, like so:
gem install gem-name -- --gem-option
So what you want to run in order to achieve installing pg with the --with-pg-config option is:
gem install pg -v '0.12.2' -- --with-pg-config=/usr/pgsql-9.2/bin/pg_config
EDIT
Also, one last tip, after searching a bit more about this issue I found that your ruby version and architecture might affect pg's installation, I'm quoting this link:
I was hesitant to uninstall everything so I just uninstalled Ruby and reinstalled with the option set to 64-bit only (platform: "x86_64-darwin12.2.0"). After reinstalling Ruby with this option, the PG gem installed without hitch and I am back to being happy.

ERROR: Error installing jekyll: ERROR: Failed to build gem native extension

My system has:
ruby 2.0.0p451 (2014-02-24) [x64-mingw32]
gem -version 2.2.2
devKit : DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe
When I try to run gem install jekyll, I get this error:
D:\devKit>gem install jekyll
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing jekyll:
ERROR: Failed to build gem native extension.
"D:/Program Files (x86)/Ruby200-x64/bin/ruby.exe" extconf.rb
D:/Program Files (x86)/Ruby200-x64/bin/ruby.exe: invalid switch in RUBYOPT: -F (
RuntimeError)
extconf failed, exit code 1
Gem files will remain installed in D:/Program Files (x86)/Ruby200-x64/lib/ruby/g
ems/2.0.0/gems/fast-stemmer-1.0.2 for inspection.
Results logged to D:/Program Files (x86)/Ruby200-x64/lib/ruby/gems/2.0.0/extensi
ons/x64-mingw32/2.0.0/fast-stemmer-1.0.2/gem_make.out
I got this error while installing Jekyll on Linux (Mint 17, which is based on Ubuntu 14.04).
I eventually found the solution here. I needed both the ruby-dev package and nodejs (the latter due to a bug in Jekyll).
sudo apt-get install ruby ruby-dev make
sudo gem install jekyll --no-rdoc --no-ri
sudo apt-get install nodejs
I ran into this problem too. Running the following installed Jekyll for me:
$ \curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled
$ sudo gem install jekyll
This installs RVM, updates Rails and installs Jekyll.
BTW - Most of the posts I've found indicate it's a problem with Xcode not having the developer tools installed. I have a newer MacBook Pro on which this stuff was installed by default, so attempting to install the Xcode dev tools did nothing for me (unlike the above, which did everything I needed).
try
gem update
then
gem install jekyll
And you may want to try with Ruby 1.9.3 and compatible DevKit.

error while installing fastthread from ruby gem . How to remove the error?

gem install fastthread -v1.0.7
Building native extensions. This could take a while...
ERROR: Error installing fastthread:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
extconf.rb:8:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:8
Gem files will remain installed in /var/lib/gems/1.8/gems/fastthread-1.0.7 for inspection.
Results logged to /var/lib/gems/1.8/gems/fastthread-1.0.7/ext/fastthread/gem_make.out
This is what I got when I tried installing from fastthread to set up SUP mail client on my system . How to get rid of this error?
Install these and then try re-installing:
sudo apt-get install ruby1.8-dev
Try this link http://kenno.wordpress.com/2009/07/25/fixed-extconf-rb8in-require-no-such-file-to-load-mkmf-loaderror/
I was getting this same error in OS X Lion. Having Xcode 4.3 installed doesn't cut it. You have to go to preferences in Xcode and install the command line tools, which installs the necessary compiler tools for doing native builds on the system. After I did this, then gem install fastthread worked for me.
Just to add to this, on debian and ubuntu the "complete" ruby package is this:
ruby1.8 ruby1.8-dev ri1.8 rdoc1.8 irb1.8 ruby1.8-elisp
ruby1.8-examples libdbm-ruby1.8 libgdbm-ruby1.8 libtcltk-ruby1.8
libopenssl-ruby1.8 libreadline-ruby1.8
So something like
sudo aptitude install ruby1.8 ruby1.8-dev ri1.8 rdoc1.8 irb1.8 ruby1.8-elisp ruby1.8-examples libdbm-ruby1.8 libgdbm-ruby1.8 libtcltk-ruby1.8 libopenssl-ruby1.8 libreadline-ruby1.8
Will save you a lot of time when doing bundle install on a large project.

Resources