代码之家  ›  专栏  ›  技术社区  ›  Xiong Chiamiov

“bundle exec”抱怨gem未安装,即使在“bundle install”之后

  •  9
  • Xiong Chiamiov  · 技术社区  · 11 年前

    我有一个网站使用 Jekyll with Github Pages 在之前在另一台计算机上搞乱版本和RVM之后,在这台计算机上,我选择只使用一个版本的Ruby和使用bundler的每个项目环境。

    我有一个很简单的 Gemfile :

    [$]> cat Gemfile
    source 'https://rubygems.org'
    gem 'github-pages'
    

    和bundler配置:

    [$]> cat .bundle/config
    ---
    BUNDLE_PATH: env
    BUNDLE_DISABLE_SHARED_GEMS: '1'
    

    当我通过运行任何命令(jekyll、gem、irb)时 bundle exec ,我得到一个依赖项错误:

    [$]> bundle exec jekyll
    Could not find RedCloth-4.2.9 in any of the sources
    Run `bundle install` to install missing gems.
    

    但是,捆绑包已安装:

    [$]> bundle install
    Using RedCloth 4.2.9
    Using i18n 0.6.11
    Using json 1.8.1
    [snip]
    Using github-pages 29
    Using bundler 1.7.7
    Your bundle is complete!
    It was installed into ./env
    

    我对bundler在使用一个子命令时如何认为gem已安装,而在使用另一个子命令的时候却认为它们已丢失感到有些困惑。

    [$]> which ruby
    /usr/local/bin/ruby
    [$]> which bundler
    /usr/local/bin/bundler
    [$]> ruby --version
    ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
    [$]> bundler --version
    Bundler version 1.7.7
    
    4 回复  |  直到 11 年前
        1
  •  5
  •   Xiong Chiamiov    11 年前

    删除 env 我注意到它为两个Ruby版本2.1.0和2.2.0创建了子目录。后者是我当前版本的Ruby,但目录是空的(所有gem都安装在 env/ruby/2.1.0/gems 目录)。这一点,再加上奥利弗关于rbenv的回答,让我开始思考不匹配的版本。

    我用一个简单的 gem install bundler ,雷兰 bundle install ,一切都很好。

    总的来说,答案似乎是解决为不同于实际使用的Ruby版本安装bundler的问题。对我来说,这似乎很奇怪 捆绑安装 另一个用于 bundle exec ,但耸耸肩。

        2
  •  4
  •   Oliver Pearmain    10 年前

    安装后我遇到了完全相同的问题 rbenv 作为我的Ruby经理。最后,我通过以下方式解决了问题:

    rbenv rehash
    

    (此外,根据@joel glovier的评论,您可能需要重新启动终端)

    它抱怨Redcloth 4.2.9的事实实际上是在转移注意力。Bundler可能找不到任何宝石,但Redcloth是它查找的第一个宝石,因此它会立即退出并返回错误。

    基本上,我已经安装了rbenv和ruby 2.2.2,并使用 rbenv global 2.2.2 但我忘了跑步 rbenv rehash 。所以我猜跑步时 bundle install 它正在查看我以前使用的ruby(systemruby)版本,以了解安装了什么gem,但在运行时 bundle exec jekyll serve 它在看我的新红宝石版本,没有发现任何宝石。

        3
  •  1
  •   David B.    10 年前

    我必须打开 ./.bundle/config 和设置 BUNDLE_DISABLE_SHARED_GEMS 到 true 以便将宝石捆绑在一起,以便在本地正确存储。

        4
  •  0
  •   Mika    10 年前

    我已经定义了 BUNDLE_GEMFILE = /home/app/current/Gemfile 在.bashrc文件中。这在将新版本部署到服务器时破坏了捆绑包exec。检查 env 你没有 BUNDLE_GEMFILE 在环境变量中定义。

    我添加了 BUNDLE_文件 到.bashrc文件中,以便于使用monit命令。现在我只在monit命令的开头定义变量。