【问题标题】:Trouble with gem installationsgem安装问题
【发布时间】:2018-12-16 02:51:35
【问题描述】:

我在一个编码训练营中,遇到了一个我很难修复的错误。我目前正在学习如何创建动态路线的练习。每次我运行我的服务器时,当我转到我的路线时都会遇到错误,它指出:

Could not find nokogiri-1.8.2 in any of the sources
Run `bundle install` to install missing gems.

在将nokogiri 添加到我的 gemfile 之后,我尝试bundle install,但我得到的只是下面的这个错误。我需要一些帮助,因为我不知道发生了什么,而且我对这些东西完全是个菜鸟。

Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.5
Ignoring websocket-driver-0.7.0 because its extensions are not built. Try: gem pristine websocket-driver --version 0.7.0
Fetching gem metadata from http://rubygems.org/........
Using rake 12.3.0
Using concurrent-ruby 1.0.5
Using i18n 0.9.5
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.1.5
Using activemodel 5.1.5
Using arel 8.0.0
Using activerecord 5.1.5
Using public_suffix 3.0.2
Using addressable 2.5.2
Using bundler 1.16.6
Using mini_mime 1.0.0
Using mini_portile2 2.3.0
Fetching nokogiri 1.8.2
Installing nokogiri 1.8.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/Users/kenkuts/.rvm/gems/ruby-2.5.0/gems/nokogiri-1.8.2/ext/nokogiri
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r
./siteconf20181215-54662-1izm05e.rb extconf.rb --use-system-libraries
Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine
unf_ext --version 0.0.7.5
Ignoring websocket-driver-0.7.0 because its extensions are not built. Try: gem
pristine websocket-driver --version 0.7.0
checking if the C compiler accepts ... *** 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.3/usr/bin/$(RUBY_BASE_NAME)
    --help
    --clean
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:456:in
`try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:571:in
`block in try_compile'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:522:in
`with_werror'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:571:in
`try_compile'
    from extconf.rb:138:in `nokogiri_try_compile'
    from extconf.rb:162:in `block in add_cflags'
from
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:629:in
`with_cflags'
    from extconf.rb:161:in `add_cflags'
    from extconf.rb:410:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

/Users/kenkuts/.rvm/gems/ruby-2.5.0/extensions/universal-darwin-18/2.3.0/nokogiri-1.8.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/kenkuts/.rvm/gems/ruby-2.5.0/gems/nokogiri-1.8.2 for inspection.
Results logged to
/Users/kenkuts/.rvm/gems/ruby-2.5.0/extensions/universal-darwin-18/2.3.0/nokogiri-1.8.2/gem_make.out

An error occurred while installing nokogiri (1.8.2), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.8.2' --source 'http://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  capybara was resolved to 2.18.0, which depends on
    xpath was resolved to 3.0.0, which depends on
      nokogiri

【问题讨论】:

    标签: ruby macos rubygems nokogiri


    【解决方案1】:

    您可能需要从 App Store 下载 Xcode,然后运行命令

    xcode-select --install
    sudo xcodebuild -license`
    

    nokogiri 安装说明提到了这一点:

    https://www.nokogiri.org/tutorials/installing_nokogiri.html#install_with_included_libraries__recommended_

    【讨论】:

    • 有趣的是我已经安装了它,它仍然给我一个错误。
    • @Kenkuts 当你 gem install nokogiri 时它会给你哪个错误?
    • 如果您使用 Homebrew,我过去曾使用过 brew install libiconv 和 brew install libyaml 帮助
    • @JayDorsey 我注意到我安装了 xcode 但没有安装 gcc。如果我安装 gcc 会缓解这个问题吗?
    • @Kenkuts 是的,您可能还需要 gcc。可能还有其他一些依赖项(可能是 libxml2)。
    【解决方案2】:

    这不是一个“答案”,而是一组(希望)有用的东西太长而无法发表评论。

    沙盒你的宝石

    我现在总是按以下方式运行 bundler,这样一个项目的依赖关系就不会影响我在系统范围内使用的 gems 或其他项目:

    bundle install --binstubs --path=vendor.noindex
    

    这会将所有可执行文件放在PROJECT_DIR/bin 中,并将所有gem 放在PROJECT_DIR/vendor.noindex 中。 “noindex”位阻​​止 Spotlight 索引 gem。运行 rspec 现在是:

    bin/rspec
    

    要从头开始,我运行:

    rm -rf .bundle bin Gemfile.lock vendor.noindex
    

    注意:请务必小心使用rm -rf!!!!

    安装和查找依赖项

    上次我使用gem install 命令安装 Nokogiri 时,它看起来像这样:

    gem install nokogiri -- \
                         --use-system-libraries \ 
                         --with-xml2-include=/opt/pkg/include/libxml2 \
                         --with-xml2-lib=/opt/pkg/lib \
                         --with-xslt-include=/opt/pkg/include/libxslt \
                         --with-xslt-lib=/opt/pkg/lib
    

    正如其他评论者所注意到的,这表明您需要安装 XCode(总是值得检查更新),并且我使用了由另一个包管理器安装的库(我在上面使用了 pkgrsc,尽管你可以使用 @987654322 @ 或 Homebrew 或者其他一些)。

    要找到您需要链接以尝试运行的库:

    find `/usr` -name libxml2 -type d 2> >(grep -v 'Permission denied' >&2)
    

    如果您通过 pkgsrc/Macports/Fink 等方式安装,则将/usr 更改为/opt。根据权限,您可能需要在前面放置sudo。

    还有locate 命令,例如

    locate libxml2
    

    这会带来很多东西。

    【讨论】:

      猜你喜欢
      • 2015-11-10
      • 2013-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-21
      • 2011-08-02
      • 1970-01-01
      相关资源
      最近更新 更多