【问题标题】:Issues installing gems when using Bundler's binstubs使用 Bundler 的 binstub 时安装 gem 的问题
【发布时间】:2012-12-14 15:28:54
【问题描述】:
  • 捆绑器 v1.2.3
  • RubyGems v1.8.24
  • RVM(最新)
  • 导轨 v3.2.9

我在我的 Rails 应用程序中使用 binstubs 和这些默认值 (~/bundle/config):

---
BUNDLE_PATH: .bundle
BUNDLE_BIN: .bundle/bin

然后我将 .bundle/bin 添加到 $PATH(通过 chwd 上的 zsh 脚本,所以这不是一个巨大的安全漏洞)所以我有正确的 gem 二进制文件可用。

除了两个问题之外,这基本上没问题。

问题 1

当我 cd 进入应用程序并输入 gem list 时,我会得到一个全局安装的 gems 列表(不是应用程序的 gems)。对于应用程序 gem,我需要输入 bundle exec gem list 并且它可以工作。我可以忍受。

问题 2

我无法安装任何本地(应用程序的本地)gem,它们位于捆绑包之外(即它们不在 Gemfile 中)。 gem-ctags gem 就是一个这样的例子。

理论上我可以将它安装到与所有其他本地 gem 相同的目录中:

gem install --install-dir .bundle/ gem-ctags

但是我没有办法使用它,就是输入这个命令:

☺ gem ctags
ERROR:  While executing gem ... (RuntimeError)
    Unknown command ctags

☹ bundle exec gem ctags
ERROR:  While executing gem ... (RuntimeError)
    Unknown command ctags

有没有办法让它工作?

PS:

  • 当我将 gem-ctags 安装到全局 gem 中,然后执行 gem ctags 时,它会正常工作)
  • 我知道 rubygems-bundler,但我宁愿只让 binstubs 工作而不是使用它(除非没有其他方法......)

更新

问题 3

gem cleanup 不起作用,即使我的 $GEM_PATH 设置正确(如 @mpapis 建议的那样):

☺ gem cleanup                                                                       
Cleaning up installed gems...
Attempting to uninstall rake-10.0.0
Unable to uninstall rake-10.0.0:
    Gem::InstallError: gem "rake" is not installed
Attempting to uninstall ffi-1.1.5
Unable to uninstall ffi-1.1.5:
    Gem::InstallError: gem "ffi" is not installed
Attempting to uninstall dalli-2.2.1
Unable to uninstall dalli-2.2.1:
    Gem::InstallError: gem "dalli" is not installed
Clean Up Complete

当我输入 gem install 时,我可以看到所有这些 gem 都已安装。

【问题讨论】:

    标签: ruby-on-rails-3 rubygems rvm bundler


    【解决方案1】:

    如果你想使用.bundle/,你需要将gem放入Gemfile

    您正在尝试使用 GEM_PATH 之外的 ruby​​gems 插件,以使其正常工作,您必须这样做:

    export GEM_PATH="$GEM_PATH:$PWD/.bundle"
    

    第三季度更新:

    根据帮助:

    $ gem help cleanup
    ...
      Description:
        The cleanup command removes old gems from GEM_HOME.  If an older version is
        installed elsewhere in GEM_PATH the cleanup command won't touch it.
    

    这意味着你需要这个:

    export GEM_HOME="$PWD/.bundle"
    

    作为副作用,它应该消除对 --install-dir .bundle/ 的需要

    只是让您知道 - 您正在为 bundler 和 ruby​​gems 做一些意想不到的事情,而且 RVM 显然还没有为您的流程做好准备。

    【讨论】:

    • 发现了另一个问题——问题 3(更新了问题)。也许您会知道是什么原因造成的?
    • 再次感谢您!这几乎就像我想象的那样工作;) 有一些与在 rvm 中弄乱 $GEM_HOME 有关的小问题,但到目前为止我对此表示满意。让我们看看它会持续多久;)
    【解决方案2】:

    作为参考,我在 zsh 中动态.bundle/bin 添加到$PATH.bundle$GEM_PATH 以使一切正常运行(即上述两个问题都已解决):

    export DEFAULT_GEM_HOME=$GEM_HOME
    
    autoload -U add-zsh-hook
    add-zsh-hook chpwd chpwd_add_binstubs_to_paths
    
    function chpwd_add_binstubs_to_paths {
      # always delete from $OLDPWD (.bundle/bin/ from $PATH and .bundle/ from $GEM_PATH)
      export PATH=${PATH//$OLDPWD\/\.bundle\/bin:}
      export GEM_PATH=${GEM_PATH//$OLDPWD\/\.bundle:}
      export GEM_HOME=$DEFAULT_GEM_HOME
    
      if [ -r $PWD/Gemfile.lock ] && [ -d $PWD/.bundle/bin ]; then
        # add .bundle/bin to $PATH and .bundle/ to $GEM_PATH (deleting existing entries first)
        export PATH=$PWD/.bundle/bin:${PATH//$PWD\/\.bundle\/bin:}
        export GEM_PATH=$PWD/.bundle:${GEM_PATH//$PWD\/\.bundle:}
        export GEM_HOME=$PWD/.bundle
      fi
    }
    
    # initially execute `chpwd_add_binstubs_to_paths` as we might be opening a new shell in Rails project's directory
    chpwd_add_binstubs_to_paths
    

    【讨论】:

      猜你喜欢
      • 2014-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      • 1970-01-01
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多