RVM 1.9.1 & nokogiri

2019-06-17 17:58发布

问题:

Having trouble installing the nokogiri gem under rvm ruby 1.9.1.

gem install nokogiri

I'm getting ...

/usr/include/libxml2... no
libxml2 is missing.  try 'port install libxml2' or 'yum install libxml2-devel'
*** extconf.rb failed ***

but i checked:

sudo apt-get install libxml2

and i got:

Reading state information... Done
libxml2 is already the newest version.

is this a root thing perhaps? RVM runs everything in userspace.

回答1:

You might want to confirm that the version of libxml installed by apt is current. Nokogiri likes nice fresh versions of libxml, so I built my libxml install from source.

nokogiri -v will tell you what you're using.



回答2:

A simpler solution:

sudo apt-get install libxslt-dev libxml2-dev


回答3:

I ran into a similar problem using homebrew on Mac.

Here's the code that does the trick, a small extension of the Nokogiri installation instructions for homebrew. Basically, you need to include a directive to tell nokogiri to use the homebrew libxml dirs. Make sure you point to the correct version of libxml2 installed by homebrew, which for me was 2.7.8:

brew install libxml2

brew link libxml2 #this may be enough but didn't work for me with rvm

#explicitly tell nokogiri to use you homebrew libxml2 rather than system
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26