ruby - Bundler 安装已安装的 gem

标签 ruby gem chef-infra bundler

我相信我误解了 bundler 的工作方式,但是从 bundle install documentation它似乎表明 bundler 将使用本地安装的系统 gems。

...

--system: Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application

...

The --system option is the default. Pass it to switch back after using the --path option as described below.

我没有使用 rbenv/rvm 或任何其他 Ruby 版本管理器。我使用 ChefDK 作为我的主要开发环境,它附带了 Ruby 和一堆预装的 gem。

Gemfile的全部内容,还没有Gemfile.lock。

source 'https://rubygems.org'

gem 'nokogiri', '1.6.3.1'

安装本地 nokogiri

$ gem list --local | grep nokogiri
nokogiri (1.6.6.2, 1.6.3.1, 1.5.5)

系统 Gem 位置已安装 nokogiri 1.6.3.1

$ echo $GEM_HOME
/Users/arthur/.chefdk/gem/ruby/2.1.0
$ find /Users/arthur/.chefdk/gem/ruby/2.1.0 | grep nokogiri | grep 1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/cache/nokogiri-1.6.3.1.gem
/Users/arthur/.chefdk/gem/ruby/2.1.0/extensions/x86_64-darwin-12/2.1.0/nokogiri-1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/extensions/x86_64-darwin-12/2.1.0/nokogiri-1.6.3.1/mkmf.log
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1/.autotest
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1/.editorconfig
...

但是,当我运行 bundle 安装时,它会尝试为 nokogiri 安装和编译 libxml2。

$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using mini_portile 0.6.0
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
  - 0001-Fix-parser-local-buffers-size-problems.patch
  - 0002-Fix-entities-local-buffers-size-problems.patch
  - 0003-Fix-an-error-in-previous-commit.patch
  - 0004-Fix-potential-out-of-bound-access.patch
  - 0005-Detect-excessive-entities-expansion-upon-replacement.patch
  - 0006-Do-not-fetch-external-parsed-entities.patch
  - 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
  - 0008-Improve-handling-of-xmlStopParser.patch
  - 0009-Fix-a-couple-of-return-without-value.patch
  - 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
  - 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.
...

我错过了什么?如何强制 bundler 使用已安装的 nokogiri 1.6.3.1(ChefDK 附带)?我试图避免让 nokogiri 编译 libxml2,因为它在许多不同的开发人员/操作工作站上一直失败,并且导致了无尽的悲伤。谢谢。

编辑

感谢 Tim Moore,使用 bundle env 我在输出中注意到 bundler 已禁用共享 gem。

$ bundle env
Bundler 1.7.12
Ruby 2.1.4 (2014-10-27 patchlevel 265) [x86_64-darwin12.0]
Rubygems 2.4.4
GEM_HOME /Users/arthur/.chefdk/gem/ruby/2.1.0
GEM_PATH /Users/arthur/.chefdk/gem/ruby/2.1.0:/opt/chefdk/embedded/lib/ruby/gems/2.1.0

Bundler settings
  disable_shared_gems
    Set for the current user (/Users/arthur/.bundle/config): "1"


Gemfile
source 'https://rubygems.org'
...

查看 ~/.bundle/config,果然全局配置已设置。

---
BUNDLE_DISABLE_SHARED_GEMS: '1'

删除后,Bundler 会正确解析 nokogiri 1.6.3.1,并且不会尝试重新安装它。默认情况下不应存在此设置,默认情况下 bundle 程序使用 --system 安装。我一定是在几个月前设置了这个设置,但忘记了。

最佳答案

尝试运行 bundle env 以验证安装位置是否符合您的预期。

如果没有,请检查是否有 .bundle/config~/.bundle/config 文件覆盖了安装路径。 bundle env 的输出会告诉您它正在使用什么配置以及它是如何确定的(即它在哪个文件中或者它是否是从环境变量中获取的)。

关于ruby - Bundler 安装已安装的 gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29033106/

相关文章:

ruby-on-rails - rails 想使用 PG 但指定了 mysql

mysql - 我如何告诉 linux bash 忽略反引号?

amazon-web-services - 使用 cloudformation 为具有 Chef 角色的节点添加标签

ruby-on-rails - XML运行时错误: Illegal character '&' in raw string?

ruby-on-rails - 安装eventmachine(1.0.3)时出错,Bundler无法继续

ruby - 安装 json gem : The 'json' native gem requires installed build tools 时出错

ruby - 为什么 Chef 不逐行执行 Recipe ?

ruby - Nokogiri 如何提取抓取的 HTML 文档的字符集编码?

javascript - 使用 Javascript 更改提交按钮的文本

ruby-on-rails - 有没有 "Ruby on Rails gem"这样的东西?