Install nokogiri ruby โ€‹โ€‹gem with native extension

I want to install a ruby โ€‹โ€‹stone that is trying to build its own extension. The gem in this case is Nokogiri. If I do gem install nokogiri, the native extension is dynamically linked to libxml, libxslt libs. I want to statically reference these libraries. How can I do it?

+4
source share
7 answers

Here are a few pointers, but itโ€™s not easy if nokogiri does not contain build flags for support:

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

    gem install nokogiri -- --with-static-libxml 
  • If there is no built-in support, you can try setting up the links used to set the gem using:

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

    The build will probably fail because -with-ldflags overrides all LDFLAGS and also '-static' tries to link everything as static, so you need to examine mkmf.log and process it accordingly.

  • If you want to do this manually, one way to do this is to fail the gem installation by calling an invalid parameter, for example:

     gem install nokogiri -- --with-ldflags 

    This will cause the installation to fail with the following message:

     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 complete the installation (see gem help install ):

      gem spec ../../cache/nokogiri-1.4.1.gem --ruby > \ ../../specifications/nokogiri-1.4.1.gemspec 
+5
source

Try:

 sudo apt-get install libxslt-dev libxml2-dev 

I solve this problem.

+5
source

To install nokogiri gem you first 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 

Then you need to install the package

 bundle install 

Last but not least, the installed pearls must be defined in your gemfile

 gem 'nokogiri' 

These steps worked flawlessly for me.

+3
source

Msg error: error: nokogiri installation error: error: failed to create gem native extension .

I fixed this problem by simply executing the following two commands:

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

And it worked perfectly .. !! :)

+2
source

If you use RVM, run the rvm requirements and set the list of libraries to # For Ruby / Ruby HEAD.

This should work

+1
source

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

Indeed, the problem here is that this nokogiri depends on libxml1, but libxml2 is installed by default ....

0
source

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

0
source

Source: https://habr.com/ru/post/1308409/


All Articles