简体   繁体   English

rails:在Mac OSX Yosemite上安装nokogiri失败

[英]rails : install nokogiri fails on Mac OSX Yosemite

I installed Rails 4.2.3 on Mac OS X Yosemite, but when I try to start the server, I get this error message 我在Mac OS X Yosemite上安装了Rails 4.2.3,但是当我尝试启动服务器时,出现此错误消息

Companys-MacBook-Pro:App MyUser$ rails server
Could not find nokogiri-1.6.1 in any of the sources
Run `bundle install` to install missing gems.
Companys-MacBook-Pro:App MyUser$

so I tried this 所以我尝试了这个

sudo gem install nokogiri -v=1.6.1

then I got these errors 然后我得到了这些错误

Companys-MacBook-Pro:~ MyUser$ sudo gem install nokogiri -v=1.6.1
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin14.4.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin14.4.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin14.4.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... OK
Running 'compile' for libxslt 1.1.26... OK
Running 'install' for libxslt 1.1.26... OK
Activating libxslt 1.1.26 (from /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin14.4.0/libxslt/1.1.26)...
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for xmlParseDoc() in -lxml2... no
-----
libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-libxslt-config
--without-libxslt-config
--with-pkg-config
--without-pkg-config
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-pkg-config
--without-pkg-config
--with-libiconv-config
--without-libiconv-config
--with-pkg-config
--without-pkg-config
--with-iconvlib
--without-iconvlib
--with-xml2lib
--without-xml2lib


Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1/ext/nokogiri/gem_make.out
Companys-MacBook-Pro:~ MyUser$ 

I then followed the instructions on nokogiri website to install libxslt, libxml2, and libiconv 然后,我按照nokogiri网站上的说明安装了libxslt,libxml2和libiconv

Companys-MacBook-Pro:~ MyUser$ brew install libxml2
Warning: libxml2-2.9.2 already installed
Companys-MacBook-Pro:~ MyUser$ brew install libxslt
Warning: libxslt-1.1.28_1 already installed
Companys-MacBook-Pro:~ MyUser$ brew install libiconv
Error: No available formula for libiconv 
==> Searching formulae...
==> Searching taps...
Companys-MacBook-Pro:~ MyUser$ 

and still no luck. 仍然没有运气。 I also tried 我也试过

Companys-MacBook-Pro:~ MyUser$ sudo gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.6.2
Parsing documentation for nokogiri-1.6.6.2
unable to convert "\xCA" from ASCII-8BIT to UTF-8 for lib/nokogiri/nokogiri.bundle, skipping
1 gem installed
Companys-MacBook-Pro:~ MyUser$ 

but rails server still does not start because it requires nokogiri 1.6.1 但是Rails服务器仍然无法启动,因为它需要nokogiri 1.6.1

Companys-MacBook-Pro:App MyUser$ rails server
Could not find nokogiri-1.6.1 in any of the sources
Run `bundle install` to install missing gems.
Companys-MacBook-Pro:App MyUser$ 

Anyone has an idea what's going on here? 有人知道这里发生了什么吗?

EDIT 1 I did run bundle install and still the same issue ; 编辑1 this is the output 这是输出

Companys-MacBook-Pro:App MyUser$ bundle install
Fetching gem metadata from http://rubygems.org/............
Fetching version metadata from http://rubygems.org/...
Fetching dependency metadata from http://rubygems.org/..
Resolving dependencies...
Using rake 0.9.2.2
Using multi_json 1.0.3
Using activesupport 3.1.0
Using bcrypt-ruby 3.0.0
Using builder 3.0.0
Using i18n 0.6.0
Using activemodel 3.1.0
Using erubis 2.7.0
Using rack 1.3.2
Using rack-cache 1.0.3
Using rack-mount 0.8.3
Using rack-test 0.6.1
Using hike 1.2.1
Using tilt 1.3.3
Using sprockets 2.0.0
Using actionpack 3.1.0
Using mime-types 1.16
Using polyglot 0.3.2
Using treetop 1.4.10
Using mail 2.3.0
Using actionmailer 3.1.0
Using arel 2.2.1
Using tzinfo 0.3.29
Using activerecord 3.1.0
Using activeresource 3.1.0
Using addressable 2.3.6
Using bundler 1.10.6
Using coderay 1.0.8
Using coffee-script-source 1.1.2
Using execjs 1.2.4
Using coffee-script 2.2.0
Using rack-ssl 1.3.2
Using rdoc 3.9.4
Using thor 0.14.6
Using railties 3.1.0
Using coffee-rails 3.1.0
Using crack 0.3.1
Using diff-lcs 1.1.3
Using multipart-post 1.2.0
Using faraday 0.7.6
Using git 1.2.6
Using hashie 1.2.0
Using oauth2 0.5.2
Using github_api 0.4.10
Using highline 1.6.21
Using mini_portile 0.5.3
Installing nokogiri 1.6.1 with native extensions

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-xml2-dir=/usr --with-xslt-dir=/opt/local --with-iconv-dir=/opt/local
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin14.4.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /private/var/folders/x4/01wntm8j66lf6mwbtmg8t3lm0000gn/T/bundler20150801-30338-1m943xrnokogiri-1.6.1/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin14.4.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin14.4.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... OK
Running 'compile' for libxslt 1.1.26... OK
Running 'install' for libxslt 1.1.26... OK
Activating libxslt 1.1.26 (from /private/var/folders/x4/01wntm8j66lf6mwbtmg8t3lm0000gn/T/bundler20150801-30338-1m943xrnokogiri-1.6.1/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin14.4.0/libxslt/1.1.26)...
checking for libxml/parser.h... no
-----
libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--with-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-libxslt-config
--without-libxslt-config
--with-pkg-config
--without-pkg-config
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-pkg-config
--without-pkg-config
--with-libiconv-config
--without-libiconv-config
--with-pkg-config
--without-pkg-config


Gem files will remain installed in /var/folders/x4/01wntm8j66lf6mwbtmg8t3lm0000gn/T/bundler20150801-30338-1m943xrnokogiri-1.6.1/gems/nokogiri-1.6.1 for inspection.
Results logged to /var/folders/x4/01wntm8j66lf6mwbtmg8t3lm0000gn/T/bundler20150801-30338-1m943xrnokogiri-1.6.1/gems/nokogiri-1.6.1/ext/nokogiri/gem_make.out
An error occurred while installing nokogiri (1.6.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.1'` succeeds before bundling.
Companys-MacBook-Pro:App MyUser$

One of issues was that you were manually installing Nokogiri 1.6.6.2, but not including the nokogiri gem entry in your Gemfile. 问题之一是您手动安装了Nokogiri 1.6.6.2,但未在Gemfile中包括nokogiri gem条目。 Bundler will specifically only show your app the gems that are listed in the file. Bundler专门只向您的应用程序显示文件中列出的宝石。

It wasn't clear to me if you were tied to nokogiri 1.6.1 because it was a dependency of another gem. 我不清楚您是否绑定到nokogiri 1.6.1,因为它是另一个gem的依赖项。 If there was another gem calling for 1.6.1 then you would investigate a newer version of that gem, which hopefully depended on the newer Nokogiri. 如果还有另一个gem要求1.6.1,那么您将研究该gem的较新版本,希望它依赖于较新的Nokogiri。 bundle update <othergem> would attempt to do so. bundle update <othergem>会尝试这样做。

Just wanted to be clear that I wasn't suggesting modifying another gem's dependencies in your lock file as they were set for a reason by that gem's author. 只是想清楚一点,我不建议您修改锁定文件中另一个gem的依赖项,因为它们是由该gem的作者设置的。

Since you initially specified gem 'nokogiri', '~> 1.6.1' in your Gemfile you were locked to that after the first bundle install. 由于您最初gem 'nokogiri', '~> 1.6.1'指定了gem 'nokogiri', '~> 1.6.1' ,因此您在首次安装捆绑软件后便将其锁定。 bundle update nokogiri would try to update you to the latest. bundle update nokogiri会尝试将您更新到最新版本。 Or manually changing the Gemfile to 1.6.6.2 or more loosely ~> 1.6 or 1.6.6. 或者手动将Gemfile松散地更改为1.6.6.2或更高版本〜> 1.6或1.6.6。

Also, as @the Tin Man mentioned using sudo install to put gems into the Apple system ruby isn't the best way to go. 此外,正如@The Tin Man提到的,使用sudo install将宝石放入Apple系统红宝石不是最佳方法。 I definitely recommend using one of the Ruby version managers like RVM or rbenv as he linked in his comment. 我绝对建议使用RVM或rbenv之类的Ruby版本管理器,因为他在评论中进行了链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM