46

I've just made the switch from rvm to rbenv and I'm trying to use bundler for gem management. After running bundle install and trying to run a simple sinatra app (ruby app.rb), I get this:

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

Running bundle install again had no effect. Also tried bundle update as suggested by another question response.

This is my Gemfile:

source "http://rubygems.org"

gem "sinatra"
gem "haml"

This is what bundle show produces

* bundler (1.0.22)
* haml (3.1.4)
* rack (1.4.1)
* rack-protection (1.2.0)
* sinatra (1.3.2)
* tilt (1.3.3)

This is what my app requires:

require "rubygems"
require "bundler/setup"
require 'sinatra'

I'm convince that this is some kind of path issue where bundler and rbenv aren't playing along. I've tried looking through rbenv's documentation but was not able to find to anything.

Note: In a different sinatra app I get the following when trying to run it:

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

Supplemental info

echo $PATH
/Users/uri/.rbenv/shims:/Users/uri/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

which bundle
/Users/uri/.rbenv/shims/bundle

Update

If I do bundle install --system it works. Although I can't see this as being a viable solution.

4

10 回答 10

105

我遇到了同样的问题。一个提示是rbenv exec bundle exec command有效并且rbenv exec bundle install --path vendor/bundle有效,但是它们的前缀等价物失败了。

我擦了擦~/.rbenv,几次尝试重新开始~/.gem Gemfile.lockvendor/bundle清理完这些后,我尝试了以下方法:

rbenv install 1.9.3-p194
rbenv rehash # for paranoia's sake
rbenv global 1.9.3-p194
gem env # to check that everything was pointing at 1.9 and not the system
gem install --no-ri --no-rdoc bundler
rbenv rehash # necessary to load up the bundle executable
bundle --path=vendor/bundle

它奏效了!

我认为重要的是,因为我尝试了几次,所以从你的主目录中删除 .gem 文件。它似乎妨碍了。

于 2012-06-21T20:48:11.167 回答
23

你跑了吗

rbenv rehash

这将为所有 ruby​​ 二进制文件提供 shims,包括由 gems 安装的二进制文件。

于 2012-03-08T21:39:44.820 回答
20

添加这个

set :default_environment, {
  'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}

deploy.rb 为我工作。

http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/

于 2012-11-24T11:35:54.897 回答
6

我建议你使用 gem 'capistrano-rbenv' ( https://github.com/yyuu/capistrano-rbenv )

  1. 确保您在远程服务器中安装了“rbenv”和 ruby​​ 版本(例如 1.9.3)

  2. 在您的 config/deploy.rb (capistrano 文件)中

    require 'capistrano-rbenv'
    
  3. 在您的 Gemfile 中:

    gem 'capistrano-rbenv', '1.0.1'
    
  4. 而已。要调试它是否有效,只需运行:

    $ cap shell
    cap> which ruby
     ** [out :: 10.103.13.74] /root/.rbenv/shims/ruby
    cap> ruby -v
     ** [out :: 10.103.13.74] ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
    
于 2013-04-03T06:01:09.947 回答
2

您应该尝试使用chruby。chruby 是 RVM / rbenv 的超最小(约 80 行)替代品。与 rbenv 不同,chruby 不依赖 shims 并简单地修改PATH,GEM_HOMEGEM_PATH.

于 2012-11-21T07:14:55.213 回答
2

当我从使用 rvm 切换到 rbenv 时,我遇到了类似的问题。我发现我的捆绑器显示的宝石列表与我的gem list命令不同。首先检查您的捆绑器和 gem 正在使用哪些路径。对于捆绑器,请使用show命令并选择任何 gem。

$ bundle show ffi
/my/project/path/vendor/ruby/1.9.1/gems/ffi-1.1.5

和我的gem environment命令(部分)

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin10.8.0]
  - INSTALLATION DIRECTORY: /Users/rolf/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1

在这里,我可以看到我的 gem 指向正确的 rbenv 路径,但我的捆绑器指向我项目的供应商路径。

运行以下命令应该可以解决捆绑程序路径问题:

$ bundle install --system

Bundler 路径现在应该指向 rbenv 路径。

$ bundle show ffi
/Users/rolf/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/ffi-1.1.5

我还发现,当我运行rvm implode命令卸载 rvm 时,仍然需要更改以下文件以删除 rvm 路径:

~/.profile
~/.bashrc
~/.zshrc

如果~/.rvm路径仍然存在,您将需要删除它。

更改这些文件后,您需要打开一个新的终端会话。最后,我终于让我的捆绑器和 gem 同步了。

于 2012-12-10T07:15:15.270 回答
1

我在这里尝试了所有的东西,但对我来说发现我的用户主目录中有一个 .bundler 出于某种原因。这导致了上面的奇怪问题,其中“which”命令在 shims 路径中正确列出了 bundle,但检查 bundle -v 显示旧系统版本,而 /Users/jerimiah/.rbenv/shims/bundle 显示最新版本。我在我的主目录中删除了 .bundler,重新哈希,重新启动我的终端,一切都开始工作了。

于 2012-12-28T07:27:33.700 回答
1

只是提醒一下,rbenv与 rvm兼容,它们玩得不好。为了您的理智,如果您想使用 rbenv,请卸载 rvm。从 rbenv 自述文件:

兼容性说明:rbenv 与 rvm 不兼容。在您尝试安装 gem 之前,一切似乎都可以正常工作。问题是 rvm 实际上用 shell 函数覆盖了 gem 命令!请在使用 rbenv 之前删除对 rvm 的所有引用。

幸运的是,Wayne(rvm 创建者)提供了一个删除 rvm,使用很容易:

rvm implode

作为常规使用或:

rvmsudo rvm implode

清理 rvm 系统范围。

于 2012-09-06T14:42:57.817 回答
0

试试这个 rbenv 插件,它会让 shims 知道捆绑器路径

https://github.com/carsomyr/rbenv-bundler

于 2012-10-06T09:59:20.070 回答
0

对于遇到此问题的任何人。这是“找不到 gem 包情况 (>= 0.a) 的最简单的解决方案

命令:

gem update --system 

然后更新捆绑器命令:

bundle update --bundler
于 2020-08-13T12:20:07.637 回答