installing nokogiri ruby gem with a native extension
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?
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
Try:
sudo apt-get install libxslt-dev libxml2-dev
I resolve this problem.
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..!! :)
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....
sudo apt-get install libxslt1-dev libxml2-dev
works for me. As of July 31, 2013
精彩评论