使用“sudo gem安装nokogiri”在mac上安装nokogiri时出错

时间:2023-01-05 00:15:13

I was trying to install nokogiri because it is required for rails to be started

我试图安装nokogiri,因为启动rails是必需的

    $ rails s
/usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/spec_set.rb:90:in `block in materialize': Could not find nokogiri-1.5.5 in any of the sources (Bundler::GemNotFound)
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/spec_set.rb:83:in `map!'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/spec_set.rb:83:in `materialize'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/definition.rb:127:in `specs'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/environment.rb:27:in `specs'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-1.0.3/lib/rubygems-bundler/noexec.rb:41:in `candidate?'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-1.0.3/lib/rubygems-bundler/noexec.rb:60:in `setup'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-1.0.3/lib/rubygems-bundler/noexec.rb:75:in `<top (required)>'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:9:in `<main>'

However, it failed when I tried to install nokogiri with the command

但是,当我试图用命令安装nokogiri时失败了

$ sudo gem install nokogiri

Here is the error.

这是错误的。

    $ sudo gem install nokogiri
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

        /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for libxml/parser.h... *** 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
    --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=/usr/local/rvm/rubies/ruby-1.9.3-p194/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-libiconv-config
    --without-libiconv-config
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:970:in `block in find_header'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:969:in `find_header'
    from extconf.rb:114:in `<main>'


Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p194/gems/nokogiri-1.5.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p194/gems/nokogiri-1.5.5/ext/nokogiri/gem_make.out

2 个解决方案

#1


1  

It looks like you need to install Xcode.

看起来您需要安装Xcode。

#2


1  

The reason you're getting this error is because the nokogiri gem includes C/C++ extensions that need to be compiled on your machine before they can run.

出现这种错误的原因是nokogiri gem包含C/ c++扩展,这些扩展在运行之前需要在您的机器上进行编译。

Just installing XCode won't fix it--you need to specifically install the XCode Command Line Tools, which is a C/C++ compiler/linker toolchain that isn't installed by default when you install XCode.

仅仅安装XCode是不能修复它的——您需要专门安装XCode命令行工具,它是一个C/ c++编译器/链接器工具链,在安装XCode时默认不安装它。

There's an option to install them within a menu inside the XCode GUI, see this thread for a screenshot:

有一个选项可以在XCode GUI内的菜单中安装它们,请查看该线程的屏幕截图:

Xcode 4.4 and later install Command Line Tools

Xcode 4.4以及以后的安装命令行工具

If you've already done that, then you may need to create a symbolic link to your compiler so your OS knows where to find it:

如果您已经这样做了,那么您可能需要为编译器创建一个符号链接,以便操作系统知道在哪里找到它:

Installing nokogiri Mac OS X 10.8.2 XCode installed

安装nokogiri Mac OS X 10.8.2 XCode

#1


1  

It looks like you need to install Xcode.

看起来您需要安装Xcode。

#2


1  

The reason you're getting this error is because the nokogiri gem includes C/C++ extensions that need to be compiled on your machine before they can run.

出现这种错误的原因是nokogiri gem包含C/ c++扩展,这些扩展在运行之前需要在您的机器上进行编译。

Just installing XCode won't fix it--you need to specifically install the XCode Command Line Tools, which is a C/C++ compiler/linker toolchain that isn't installed by default when you install XCode.

仅仅安装XCode是不能修复它的——您需要专门安装XCode命令行工具,它是一个C/ c++编译器/链接器工具链,在安装XCode时默认不安装它。

There's an option to install them within a menu inside the XCode GUI, see this thread for a screenshot:

有一个选项可以在XCode GUI内的菜单中安装它们,请查看该线程的屏幕截图:

Xcode 4.4 and later install Command Line Tools

Xcode 4.4以及以后的安装命令行工具

If you've already done that, then you may need to create a symbolic link to your compiler so your OS knows where to find it:

如果您已经这样做了,那么您可能需要为编译器创建一个符号链接,以便操作系统知道在哪里找到它:

Installing nokogiri Mac OS X 10.8.2 XCode installed

安装nokogiri Mac OS X 10.8.2 XCode

相关文章