问题描述
我决定昨天升级到1.9.2 ruby,并安装了rvm来做到这一点.我运行了一些以前在1.8.7上工作过的文件,但是任何需要nokogiri的文件都会失败,并出现以下错误.
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]
我正在OSX Snow Leopard 10.6.4上运行nokogiri 1.4.3.1,ruby 1.9.2
I am running nokogiri 1.4.3.1, ruby 1.9.2 on OSX Snow Leopard 10.6.4
推荐答案
如果您从nokogiri遇到了Segmentation Fault错误,例如,当您打开Rails控制台,并且正在使用RVM并且您的ruby版本是1.9.2时, (当前为1.9.2p136),您在nokogiri分段错误消息之后注意到对ruby 1.8.7的引用,那么以下内容可能会有所帮助...
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...
错误
$ 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
解决方案
(1)确保ruby 1.8.7不是rvm ruby版本:-运行rvm list
(1) make sure that ruby 1.8.7 is not a rvm ruby version:- run rvm list
(2)卸载与nokogiri和libxml2相关的依赖项:
(2) uninstall nokogiri and libxml2 related dependencies:
$ gem uninstall nokogiri
$ brew uninstall libxml2
(3)使用自制软件安装libxml2
(3) install libxml2 using homebrew
$ brew install libxml2
$ brew link libxml2
(4)从源代码安装libxslt
(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)安装nokogiri
(5) install nokogiri
gem install nokogiri
替代方法(确保路径正确):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
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)测试
$ rails c
Loading development environment (Rails 3.0.3)
>>
获取并保持Ruby XML解析库正常运行可能是一个问题.这里有一些替代方法:LibXML,Hpricot,REXML
Getting and keeping your Ruby XML parsing libraries running properly can be an issue. Here are some alternatives: LibXML, Hpricot, REXML
这篇关于升级到ruby 1.9.2,并在nokogiri中获得Segmentation Fault错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!