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?
7 Answers
Here are some pointers, but's it's not easy unless nokogiri contains build flags to support it:
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 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.
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
-
Is there any way I can dowonload the package (gem fetch), then unpack it and modify the Makefile and then install it? Commented Apr 30, 2010 at 19:57
-
@ajstack, yes, that should be possible see gem help install, i've added it to my answer– mfazekasCommented May 5, 2010 at 11:20
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.
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..!! :)
-
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– vilpe89Commented Nov 1, 2014 at 23:56
If you're using RVM, run rvm requirements and install the list of libraries at # For Ruby / Ruby HEAD.
That should work
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....