4

I want to install a ruby gem which tries to build a native extension. The gem in this case is nokogiri. If I do gem install nokogiri, the native extension dynamically links against libxml, libxslt libs. I want to statically link against those libs. How should I go about this?

1
  • They now have a tutorial for that issue at nokogiri.org
    – Sylhare
    Commented Nov 8, 2017 at 15:51

7 Answers 7

7

Here are some pointers, but's it's not easy unless nokogiri contains build flags to support it:

  1. If nokogiri supports it, you can pass build arguments to install gem like this

    gem install nokogiri -- --with-static-libxml
    
  2. If there is no built in support you can try tweaking linkflags used to install the gem with:

    gem install nokogiri -- --with-ldflags='-static'
    

    It's likely that the build will fail, since --with-ldflags overrides all LDFLAGS, and also '-static' tries to link everything as static, so you need to examine mkmf.log, and treat it accordingly.

  3. If you want to do it manually, one way to do it is making the gem install fail by invoking with invalid option like:

    gem install nokogiri -- --with-ldflags
    

    This will cause the installation to fail with a message like this:

    Building native extensions.  This could take a while...
    ERROR:  Error installing nokogiri:
           ERROR: Failed to build gem native extension.
    
    ruby extconf.rb --with-ldflags
    

    So you should be able to build the gem yourself then after it's done finish the installation with (see gem help install):

      gem spec ../../cache/nokogiri-1.4.1.gem --ruby > \
             ../../specifications/nokogiri-1.4.1.gemspec
    
2
  • Is there any way I can dowonload the package (gem fetch), then unpack it and modify the Makefile and then install it?
    – user287468
    Commented Apr 30, 2010 at 19:57
  • @ajstack, yes, that should be possible see gem help install, i've added it to my answer
    – mfazekas
    Commented May 5, 2010 at 11:20
6

Try:

sudo apt-get install libxslt-dev libxml2-dev

I resolve this problem.

0
3

To install nokogiri gem first you need to install libxslt-dev and libxml2-dev

sudo apt-get install libxslt-dev libxml2-dev

And then install nokogiri gem

sudo gem install nokogiri

Afterwards you need to install the bundle

bundle install

Last but not least the installed gem needs to be defined within your Gemfile

gem 'nokogiri'

These steps worked flawlessly for me.

2

Error Msg : error: error installing nokogiri: error: failed to build gem native extension.

I fixed this issue just by running the these two commands :

$ sudo apt-get install libxml2 libxml2-dev libxslt libxslt-dev?
$ gem install nokogiri

And it worked fine..!! :)

1
  • Thanks! Needed to install some of those libs and then I ran the gem with command: sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri -- --use-system-libraries
    – vilpe89
    Commented Nov 1, 2014 at 23:56
1

If you're using RVM, run rvm requirements and install the list of libraries at # For Ruby / Ruby HEAD.

That should work

0

I fix this issue by: sudo apt-get install libxml++1.0-dev

The really issue here is because this nokogiri depends on libxml1, but default install is libxml2....

0

sudo apt-get install libxslt1-dev libxml2-dev works for me. As of July 31, 2013

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.