我正处于编码训练营中,并且遇到一个错误,我很难解决。我目前正在练习中,学习如何创建动态路线。每次我运行服务器时,转到路线时都会出错,并指出:
Could not find nokogiri-1.8.2 in any of the sources
Run `bundle install` to install missing gems.
在将bundle install
添加到我的gemfile之后,我尝试nokogiri
,但是我得到的只是以下错误。我需要一些帮助,因为我不知道发生了什么,而我对此东西一无所知。
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
答案 0 :(得分:1)
您可能需要从App Store下载Xcode,然后运行命令
xcode-select --install
sudo xcodebuild -license`
nokogiri安装说明提到了这一点:
答案 1 :(得分:0)
这不是“答案”,而是一系列(希望)有用的东西,对评论太久了。
我现在始终以以下方式运行捆绑程序,以使一个项目的依赖项不会影响我在系统范围内使用的gem或其他项目:
bundle install --binstubs --path=vendor.noindex
这会将所有可执行文件放在PROJECT_DIR/bin
中,所有gems放在PROJECT_DIR/vendor.noindex
中。 “ noindex”位阻止Spotlight对宝石进行索引。现在运行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, Macports或Homebrew,也许还有一些)。
要找到需要链接以尝试运行的库:
find `/usr` -name libxml2 -type d 2> >(grep -v 'Permission denied' >&2)
如果通过pkgsrc / Macports / Fink等安装,则将/usr
更改为/opt
。根据权限,您可能需要在前面放置sudo
。< / p>
还有locate
命令,例如
locate libxml2
哪个会带来很多东西。希望有帮助。