ruby Bundler 不使用 rbenv,找不到 [gem]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9602806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bundler not working with rbenv, could not find [gem]
提问by Uri
I've just made the switch from rvm to rbenvand I'm trying to use bundler for gem management. After running bundle installand trying to run a simple sinatra app (ruby app.rb), I get this:
我刚刚从 rvm 切换到rbenv,我正在尝试使用 bundler 进行 gem 管理。在运行bundle install并尝试运行一个简单的 sinatra 应用程序 ( ruby app.rb) 后,我得到了这个:
Could not find haml-3.1.4 in any of the sources
Run `bundle install` to install missing gems.
Running bundle installagain had no effect. Also tried bundle updateas suggested by another question response.
bundle install再次运行没有任何效果。也bundle update按照另一个问题回答的建议进行了尝试。
This is my Gemfile:
这是我的 Gemfile:
source "http://rubygems.org"
gem "sinatra"
gem "haml"
This is what bundle showproduces
这就是bundle show产生
* 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.
我确信这是某种路径问题,其中 bundler 和 rbenv 没有一起玩。我试过查看 rbenv 的文档,但找不到任何东西。
Note: In a different sinatra app I get the following when trying to run it:
注意:在另一个 sinatra 应用程序中,我在尝试运行它时得到以下信息:
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
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
which bundle/Users/uri/.rbenv/shims/bundle
Update
更新
If I do bundle install --systemit works. Although I can't see this as being a viable solution.
如果我这样做的bundle install --system话。虽然我不认为这是一个可行的解决方案。
回答by kweerious
I was having the same issue. One hint was that rbenv exec bundle exec commandworked and that rbenv exec bundle install --path vendor/bundleworked, but their prefixed equivalents failed.
我遇到了同样的问题。一个提示是rbenv exec bundle exec command有效并且rbenv exec bundle install --path vendor/bundle有效,但它们的前缀等价物失败了。
I wiped my ~/.rbenv, ~/.gemGemfile.lockand vendor/bundlea few times trying to start fresh. Once these were cleaned away I tried the following:
我擦拭了我的~/.rbenv,~/.gemGemfile.lock并vendor/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
and it worked!
它奏效了!
I think the important thing, since I tried this a few times, is to remove the .gem file from your home directory. It seems to get in the way.
我认为重要的是,因为我试过几次,是从你的主目录中删除 .gem 文件。它似乎妨碍了。
回答by Ben Woodall
Have you run
你跑了吗
rbenv rehash
This will provide shims for all ruby binaries, including ones installed by gems.
这将为所有 ruby 二进制文件提供垫片,包括由 gems 安装的二进制文件。
回答by thdr
Adding this
添加这个
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
to deploy.rb worked for me.
deploy.rb 对我来说有效。
http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/
http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/
回答by u445908
I suggest you use the gem 'capistrano-rbenv' (https://github.com/yyuu/capistrano-rbenv)
我建议你使用 gem 'capistrano-rbenv' ( https://github.com/yyuu/capistrano-rbenv)
make sure you have "rbenv" and a ruby version (e.g. 1.9.3) installed in remote server
in your config/deploy.rb (capistrano file)
require 'capistrano-rbenv'in your Gemfile:
gem 'capistrano-rbenv', '1.0.1'that's it. to debug if it works, just run:
$ 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]
确保您在远程服务器中安装了“rbenv”和 ruby 版本(例如 1.9.3)
在您的 config/deploy.rb(capistrano 文件)中
require 'capistrano-rbenv'在您的 Gemfile 中:
gem 'capistrano-rbenv', '1.0.1'就是这样。要调试它是否有效,只需运行:
$ 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]
回答by postmodern
回答by rlawrenz
I had a similar problem when I switched from using rvm to rbenv. I found my bundler was showing a different list of gems than my gem listcommand. First check to see which paths your bundler and gem are using. For bundler use the showcommand and select any gem.
当我从使用 rvm 切换到 rbenv 时,我遇到了类似的问题。我发现我的打包器显示的 gem 列表与我的gem list命令不同。首先检查您的 bundler 和 gem 正在使用哪些路径。对于 bundler,使用show命令并选择任何 gem。
$ bundle show ffi
/my/project/path/vendor/ruby/1.9.1/gems/ffi-1.1.5
and my gem environmentcommand (in part)
和我的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
Here I could see my gem is pointing to the correct rbenv path but my bundler is pointing to my project's vendor path.
在这里,我可以看到我的 gem 指向正确的 rbenv 路径,但我的捆绑程序指向我的项目的供应商路径。
Running the following command should fix the bundler path problem:
运行以下命令应该可以修复打包路径问题:
$ bundle install --system
Bundler path should now be pointing to the rbenv path.
Bundler 路径现在应该指向 rbenv 路径。
$ bundle show ffi
/Users/rolf/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/ffi-1.1.5
Also I found when I run the rvm implodecommand to uninstall rvm, there were still the following files which I needed to change to remove rvm paths:
我还发现,当我运行rvm implode命令卸载 rvm 时,仍然需要更改以下文件以删除 rvm 路径:
~/.profile
~/.bashrc
~/.zshrc
If the ~/.rvmpath still exists, you will need to remove this.
如果~/.rvm路径仍然存在,您将需要删除它。
You will need to open a new terminal session after changing these files. Finally after all that I finally got my bundler and gem in sync.
更改这些文件后,您将需要打开一个新的终端会话。最后,我终于让我的打包器和 gem 同步了。
回答by jerimiah797
I tried all the stuff here, but what did it for me was discovering that I had a .bundler in my user home directory for some reason. This was causing the weird problem above where the 'which' command correctly listed bundle in the shims path, but checking bundle -v showed the old system version, while /Users/jerimiah/.rbenv/shims/bundle showed the latest versions. I deleted .bundler in my home directory, rehashed, restarted my terminal, and everything started working.
我在这里尝试了所有的东西,但对我来说是什么,因为某种原因,我发现我的用户主目录中有一个 .bundler。这导致了上面的奇怪问题,其中 'which' 命令在 shims 路径中正确列出了 bundle,但检查 bundle -v 显示旧系统版本,而 /Users/jerimiah/.rbenv/shims/bundle 显示最新版本。我删除了主目录中的 .bundler,重新散列,重新启动我的终端,一切都开始工作了。
回答by ajhit406
Just a reminder too that rbenv is notcompatible with rvm they do not play nicely. For your sanity, uninstall rvm if you want to use rbenv. From the rbenv README:
也只是提醒一下,rbenv与 rvm不兼容,它们不能很好地发挥作用。为了您的理智,如果您想使用 rbenv,请卸载 rvm。来自rbenv README:
Compatibility note: rbenv is incompatible with rvm. Things will appear to work until you try to install a gem. The problem is that rvm actually overrides the gem command with a shell function! Please remove any references to rvm before using rbenv.
兼容性说明:rbenv 与 rvm 不兼容。在您尝试安装 gem 之前,事情似乎可以正常工作。问题是rvm实际上用shell函数覆盖了gem命令!请在使用 rbenv 之前删除对 rvm 的任何引用。
Luckily, Wayne (rvm creator) provides a remove rvm easily using:
幸运的是,Wayne (rvm creator) 提供了一个很容易使用的删除 rvm:
rvm implode
rvm implode
As a regular use or:
作为常规使用或:
rvmsudo rvm implode
rvmsudo rvm implode
To clean rvm system wide.
清理 rvm 系统。
回答by CodedReality
Give this rbenv plugin a try, it will make shims aware of the bundler paths
试试这个 rbenv 插件,它会让垫片知道打包路径

