ruby 捆绑包不适用于 rbenv
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28056595/
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
Bundle not working with rbenv
提问by Antarr Byrd
I'm trying to use bundler with rbenv. I has been working until today. The only thing I may have done to break it was gem pristine --allor gem cleanup? When trying to install bundler i get the following error.
我正在尝试将 bundler 与 rbenv 一起使用。我一直工作到今天。我可能为打破它所做的唯一一件事是gem pristine --all或者gem cleanup?尝试安装 bundler 时出现以下错误。
Antarrs-MacBook-Pro:some-app antarrbyrd$ sudo gem install bundler
Password:
Bundler gave the error "Could not find mail-2.5.4 in any of the sources" while processing "/Users/antarrbyrd/dev/some-app/Gemfile". Perhaps you forgot to run "bundle install"?
Successfully installed bundler-1.7.12
Parsing documentation for bundler-1.7.12
Done installing documentation for bundler after 3 seconds
1 gem installed
Antarrs-MacBook-Pro:some-app antarrbyrd$ bundle install
/Users/antarrbyrd/.rbenv/versions/2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'bundler' (>= 0) among 8 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/antarrbyrd/.gem', execute `gem env` for more information
from /Users/antarrbyrd/.rbenv/versions/2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:324:in `to_spec'
from /Users/antarrbyrd/.rbenv/versions/2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
from /usr/local/bin/bundle:22:in `<main>'
when i do rbenv rehashor rbenv bundler onit get this error
当我这样做rbenv rehash或出现rbenv bundler on此错误时
Bundler gave the error "Could not find mail-2.5.4 in any of the sources" while processing "/Users/antarrbyrd/dev/some-app/Gemfile". Perhaps you forgot to run "bundle install"?
~/.bash_profile
~/.bash_profile
export BUNDLER_EDITOR=atom
export PATH=$PATH:/usr/local/opt/android-sdk/build-tools/21.1.2
export HOMEBREW_GITHUB_API_TOKEN=...
export ANDROID_HOME=/usr/local/opt/android-sdk
export PATH="$HOME/.rbenv/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
# Allow local Gem Managment
# export GEM_HOME="$HOME/.gem"
# export GEM_PATH="$HOME/.gem"
# export PATH="$HOME/.gem/bin:$PATH"
gem env
gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.2
- RUBY VERSION: 2.1.2 (2014-05-08 patchlevel 95) [x86_64-darwin14.0]
- INSTALLATION DIRECTORY: /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
- RUBY EXECUTABLE: /usr/local/var/rbenv/versions/2.1.2/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/var/rbenv/versions/2.1.2/bin
- SPEC CACHE DIRECTORY: /Users/antarrbyrd/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-14
- GEM PATHS:
- /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
- /Users/antarrbyrd/.gem/ruby/2.1.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => false
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "-n/usr/local/bin"
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/var/rbenv/versions/2.1.2/bin
- /usr/local/Cellar/rbenv/0.4.0/libexec
- /Users/antarrbyrd/.gem/bin
- /usr/local/var/rbenv/shims
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/var/rbenv/shims
- /Users/antarrbyrd/.rbenv/bin
- /Users/antarrbyrd/.rbenv/shims
- /Users/antarrbyrd/.gem/bin
- /usr/local/opt/android-sdk/build-tools/21.1.2
update
更新
I reinstalled rbenv via brew and now I get the following error when running bundle install.
我通过 brew 重新安装了 rbenv,现在在运行 bundle install 时出现以下错误。
The `bundle' command exists in these Ruby versions:
2.1.5
response to Joel
对乔尔的回应
Antarrs-MacBook-Pro:myapp antarrbyrd$ command -v ruby
/usr/local/var/rbenv/shims/ruby
Antarrs-MacBook-Pro:myapp antarrbyrd$ command -v bundle
/usr/local/bin/bundle
Antarrs-MacBook-Pro:myapp antarrbyrd$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin14.0]
Antarrs-MacBook-Pro:myapp antarrbyrd$ bundle -v
Bundler version 1.7.12
Antarrs-MacBook-Pro:myapp antarrbyrd$
回答by joelparkerhenderson
Your installation is caught in a loop.
您的安装陷入了循环。
Change to a directory that is not your app, and that doesn't have a Gemfile.
切换到不是您的应用程序且没有 Gemfile 的目录。
Then do the usual gem install bundle(and use sudoif you need it)
然后做通常的gem install bundle(sudo如果你需要的话就使用)
Then change to your app directory, and do the usual bundle install.
然后切换到您的应用程序目录,并执行通常的bundle install.
Does that solve your issue?
这能解决你的问题吗?
If you need more help, can run these commands then paste the results in your question?
如果您需要更多帮助,可以运行这些命令然后将结果粘贴到您的问题中吗?
$ command -v ruby
$ command -v bundle
$ ruby -v
$ bundle -v
Look for any mismatch between the results and what you expect. This will help you track down what's happening. You may need to update your Gemfile Ruby version.
寻找结果与您期望的任何不匹配。这将帮助您追踪正在发生的事情。您可能需要更新您的 Gemfile Ruby 版本。
(Also, you may want to consider changing from rbenvto chrubybecause it's better IMHO with these kinds of path issues)
(此外,您可能需要考虑从 更改为rbenv,chruby因为对于此类路径问题,恕我直言更好)
回答by ChaosPredictor
I got:
我有:
rbenv: bundle: command not found
The `bundle' command exists in these Ruby versions:
2.3.0
after upgrade to Ruby 2.3.1
升级到 Ruby 2.3.1 后
and it's solved by:
它是通过以下方式解决的:
gem install rails
from working folder
从工作文件夹
回答by Vbp
gem install bundler
You need to reinstall bundler for each version of Ruby you use.
您需要为您使用的每个 Ruby 版本重新安装 bundler。
Reference: github issue
参考:github问题
回答by Salma Gomaa
Try to use:
尝试使用:
bin/bundle
箱/包
instead of
代替
bundle
捆
回答by Akshat Bajaj
Try setting ruby globally
尝试全局设置 ruby
rbenv global 2.3.1
回答by Alex Cohen
If none of the other solutions work for you try this.
如果其他解决方案都不适合您,请尝试此操作。
For some reason I could not install bundler on specific ruby versions, thus reinstalling bundler did nothing for me.
由于某种原因,我无法在特定的 ruby 版本上安装 bundler,因此重新安装 bundler 对我没有任何帮助。
However I noticed how rbenv whence bundlespecified that bundle was active in some ruby versions, but not others. If you look under the path for the gem without bundler (for me this was ~/.rbenv/versions/2.5.1/bin/) you will notice that it is not there. However under other versions that whence can recognise you will see the executable is there (for me it was there under ~/.rbenv/versions/2.3.1/bin/bundle).
但是,我注意到rbenv whence bundle该包在某些 ruby 版本中是如何指定的,但在其他版本中则不然。如果您在没有打包程序的情况下查看 gem 的路径(对我来说这是~/.rbenv/versions/2.5.1/bin/),您会注意到它不在那里。但是,在可以识别的其他版本下,您会看到可执行文件在那里(对我来说,它在 下~/.rbenv/versions/2.3.1/bin/bundle)。
Just copy the executable over from the working ruby version to the one that is broken. Then at the top of the file you will notice sha-bang is set to the other ruby version (for me this was #!/Users/myuser/.rbenv/versions/2.3.1/bin/ruby). Change the version path to the ruby version you want to fix and then it will all magically start working.
只需将可执行文件从工作的 ruby 版本复制到损坏的版本即可。然后在文件的顶部,您会注意到 sha-bang 设置为另一个 ruby 版本(对我来说是#!/Users/myuser/.rbenv/versions/2.3.1/bin/ruby)。将版本路径更改为您要修复的 ruby 版本,然后它就会神奇地开始工作。
回答by l3x
Here's what worked for me with a legacy project:
以下是对遗留项目对我有用的内容:
- Set the proper ruby version via rbenv
- 通过 rbenv 设置正确的 ruby 版本
$ cd YOUR_PROJECT_DIRECTORY
$ rbenv install 2.1.0
$ rbenv local 2.1.0
- If you still get an error when installing bundle, look for a PATH warning:
- 如果在安装 bundle 时仍然出现错误,请查找 PATH 警告:
$ gem install bundle
WARNING: You don't have /Users/lex/.gem/ruby/2.1.0/bin in your PATH,
gem executables will not run.
Successfully installed bundle-0.0.1
1 gem installed
- Update your PATH:
- 更新您的路径:
$ PATH=/Users/lex/.gem/ruby/2.1.0/bin:$PATH
- Try again:
- 再试一次:
$ bundle install
Fetching: bundler-1.11.2.gem (100%)
HTTP GET https://bundler.rubygems.org/api/v1/dependencies
HTTP 200 OK
Fetching gem metadata from https://rubygems.org/
. . .
Using sudo to install gems is generally not what you want to do.
使用 sudo 安装 gems 通常不是您想要做的。
回答by mnishiguchi
I have a similar issue today. My issue was fixed as follows:
我今天有一个类似的问题。我的问题已修复如下:
system dependencies
- rvenv
- ruby 2.5.0
- rails 5.1.6
在 Gemfile.lock 中检查 bundler 版本
BUNDLED WITH
1.17.3
安装特定版本的 bundler
$ gem install bundler -v 1.17.3
Fetching bundler-1.17.3.gem
Successfully installed bundler-1.17.3
Parsing documentation for bundler-1.17.3
Done installing documentation for bundler after 3 seconds
1 gem installed
Hope this will help somebody.
希望这会帮助某人。
回答by emson
I had a similar issue running Guard with Foreman. My original command to run it was:
我在与 Foreman 一起运行 Guard 时遇到了类似的问题。我运行它的原始命令是:
bundle exec foreman run guard -c
This gave me these errors:
这给了我这些错误:
11:07:52 - INFO - Run all
11:07:52 - INFO - Running all specs
/Users/MyUser/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'bundler' (>= 0) among 146 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/MyUser/devel/o2/vesta/vendor/bundle/ruby/2.2.0', execute `gem env` for more information
from /Users/MyUser/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
from /Users/MyUser/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
from /Users/MyUser/.rbenv/versions/2.2.0/bin/bundle:22:in `<main>'
The simple fix was to not use bundle execwith foreman but to use it against guard. e.g.
简单的解决方法是不bundle exec与工头一起使用,而是将其用于防护。例如
foreman run bundle exec guard -c
Hope this helps.
希望这可以帮助。

