1
votes

I'm on OSX Marvericks with rvm. installing native extension like nokogiri from bundler failed. But installing from gem command works.

I also installed latest XCode, Commandline Tool.

I have no clue what is difference between bundle install and gem install.

$ rvm requirements
Checking requirements for osx.
Certificates in '/usr/local/etc/openssl/cert.pem' already are up to date.
Requirements installation successful.
Yusuke-no-MacBook-Air-2:doorkeeper-jp-admin yandod$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.3.1
Using bundler 1.6.2
Using mini_portile 0.5.3

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/yandod/.rvm/rubies/ruby-2.0.0-p451-rvm/bin/ruby extconf.rb 
/Users/yandod/.rvm/rubies/ruby-2.0.0-p451-rvm/bin/ruby: invalid option -H  (-h will show valid options) (RuntimeError)

extconf failed, exit code 1

Gem files will remain installed in /Volumes/Macintosh HD 2/develop/doorkeeper-jp-admin/vendor/bundle/gems/nokogiri-1.6.1 for inspection.
Results logged to /Volumes/Macintosh HD 2/develop/doorkeeper-jp-admin/vendor/bundle/extensions/x86_64-darwin-13/2.0.0/nokogiri-1.6.1/gem_make.out
An error occurred while installing nokogiri (1.6.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.1'` succeeds before bundling. 

result for gem install.

$ gem install nokogiri -v '1.6.1'
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.1
1 gem installed

versions for related software:

$ bundle --version
Bundler version 1.6.2
$ rvm --version

rvm 1.25.25 (stable) by Wayne E. Seguin , Michal Papis  [https://rvm.io/]
$ gem --version
2.2.2

added: my bundler config

$ cat ~/.bundle/config 
BUNDLE_PATH: ./vendor/bundle
BUNDLE_BUILD__NOKOGIRI: --use-system-libraries --with-iconv-dir=/usr/local/opt/libiconv  --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xslt-config=/usr/local/opt/libxslt/bin/xslt-config
3
bundle install still fails after having installed the gem?Eduardo
it is still failing even after "gem install"Yusuke Ando
If the gem is installed, bundler shouldn't try to install it again (in these cases bundler says 'using' instead of 'installing'). It could be possible that you're running bundle installin a different ruby/gemset than the one you're running gem install nokogiri?Eduardo
I set bundle path under the project dir. $ cat ~/.bundle/config --- BUNDLE_PATH: ./vendor/bundleYusuke Ando
Ok, I think what's going on. I'll try and elaborate an answer.Eduardo

3 Answers

0
votes

When you do gem install the gem is installed to your default system location for gems (you can get that looking at the output of gem env).

But when you're doing bundle install you're installing the gem to a location other than your system's gem repository (as you have configured a custom path for your bundle BUNDLE_PATH=./vendor/bundle), so Bundler will install the gems even if they're present in the system's gem repository, because you're not using that.

Now, for some reason the gemcommand has no trouble locating the system libraries needed to build the native extensions of the gem, but Bundler has. So what you have to do is instruct Bundler the paths for those libraries.

So, assuming you're using Homebrew:

  • Make sure you have all the native dependencies installed:
    brew install libxml2 libxslt libiconv

  • Instruct Bundler how to build the nokogiri gem:
    bundle config build.nokogiri --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

  • Install the bundle, signaling nokogiri to use the aforementioned libraries: NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install

It should be it.

EDIT:

Although the above steps may remain necessary, it seems that the actual problem is the presence of 'space' characters in your project's path.

Seeing that unsetting the bundle path option make things work, I've reviewed your original bundle install output more carefully and I've got aware that you're using what it looks like an external drive with 'space' characters on its name.

Project paths including 'space' or especial chars are usually a problem for a lot of tools so you should avoid them. Please try renaming your volume or moving your project to another location.

Sorry I did not realize before.

0
votes

try: rvm get stable

then: rvm reload

0
votes

You should change the ownership of these directories to your user.

sudo chown -R $(whoami) /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig

And make sure that your user has to write permission.

chmod u+w /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig