Upgraded to ruby 1.9.2 and getting Segmentation Fault errors in nokogiri

只谈情不闲聊 提交于 2019-12-18 17:11:11

问题


I decided to upgrade to 1.9.2 ruby yesterday and also installed rvm to do it. I ran a few recent files I had working previously on 1.8.7 but anything requiring nokogiri fails with the following errors.

/Users/myusername/.rvm/gems/ruby-1.9.2-p0/gems/nokogiri-1.4.3.1/lib/nokogiri/nokogiri.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

I am running nokogiri 1.4.3.1, ruby 1.9.2 on OSX Snow Leopard 10.6.4


回答1:


If you get a Segmentation fault error from nokogiri, e.g., when you open your rails console, and you are using RVM and your ruby version is 1.9.2 something (mine currently is 1.9.2p136) and you notice a reference to ruby 1.8.7 just after the nokogiri segmentation fault message, then perhaps the following may be of assistance...

ERROR

$ rails c
/Users/lex/.rvm/gems/ruby-1.9.2-p136@lmi/gems/nokogiri-1.4.4/lib/nokogiri/nokogiri.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

Abort trap

SOLUTION

(1) make sure that ruby 1.8.7 is not a rvm ruby version: - run rvm list

if it is, then remove it: ex: rvm uninstall ree-1.8.7-2010.02

(2) uninstall nokogiri and libxml2 related dependencies:

$ gem uninstall nokogiri
$ brew uninstall libxml2

(3) install libxml2 using homebrew

$ brew install libxml2
$ brew link libxml2

(4) install libxslt from source

$ wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
$ tar -zxvf libxslt-1.1.26.tar.gz
$ cd libxslt-1.1.26
$ ./configure --prefix=/usr/local/Cellar/libxslt/1.1.26    --with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.7
$ make
$ sudo make install

(5) install nokogiri

gem install nokogiri

Alternative (ensure your paths are correct): gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26

(6) test

$ rails c
Loading development environment (Rails 3.0.3)
>>

Getting and keeping your Ruby XML parsing libraries running properly can be an issue. Here are some alternatives: LibXML, Hpricot, REXML




回答2:


I'm guessing you just need to tell rvm to use the correct ruby.

rvm 1.9.2

Otherwise why would your second line indicate 1.8.7?

You shouldn't expect native code compiled against one major version of ruby to link cleanly to another. There's no ABI contract, afaik.

  • https://rvm.io/rvm/basics/
  • https://rvm.io/rvm/cli/



回答3:


Is it possible you originally built Nokogiri on Leopard then upgraded to Snow Leopard?

If so, do a gem uninstall nokogiri followed by gem install nokogiri. That will force it to recompile for your currently selected Ruby and OS.

I saw the similar problems when I upgraded from Leopard to Snow Leopard, and reinstalled my Ruby. The gems didn't get recompiled, so I had to force several of them to do so.




回答4:


Try running rvm requirements in Terminal and see if there are any missing dependencies. (It shows in red in my OS X)

The returned notes helped me install missing dependencies with brew, with clearly stated steps.




回答5:


all the suggestions here didn't work for me, but the abridged answer to this issue by mmrobins below:

rvm gemset empty

followed by a standard bundle install got everything working for me.



来源:https://stackoverflow.com/questions/4160289/upgraded-to-ruby-1-9-2-and-getting-segmentation-fault-errors-in-nokogiri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!