捆绑不与rbenv一起使用

时间:2015-01-20 22:49:11

标签: ruby bundler rbenv

我正在尝试使用捆绑器与rbenv。我一直工作到今天。我可能做的唯一一件事就是gem pristine --allgem 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>'

当我执行rbenv rehashrbenv 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中

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

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

更新

我通过brew重新安装了rbenv,现在运行bundle install时出现以下错误。

The `bundle' command exists in these Ruby versions:
  2.1.5

对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$ 

12 个答案:

答案 0 :(得分:70)

您的安装陷入了困境。

更改为不是您的应用的目录,并且没有Gemfile。

然后执行常规gem install bundle(如果需要,请使用sudo

然后切换到您的app目录,并执行常规bundle install

这会解决您的问题吗?

如果您需要更多帮助,可以运行这些命令,然后将结果粘贴到您的问题中吗?

 $ command -v ruby
 $ command -v bundle
 $ ruby -v
 $ bundle -v

查找结果与预期之间的任何不匹配。这将帮助您追踪正在发生的事情。您可能需要更新Gemfile Ruby版本。

(另外,您可能需要考虑从rbenv更改为chruby,因为对于这些路径问题,恕我直言更好)

答案 1 :(得分:35)

我得到了:

rbenv: bundle: command not found

The `bundle' command exists in these Ruby versions:
  2.3.0
升级到Ruby 2.3.1后

它通过以下方式解决:

gem install rails

来自工作文件夹

答案 2 :(得分:12)

  

gem install bundler

您需要为您使用的每个Ruby版本重新安装bundler。

参考:github issue

答案 3 :(得分:4)

尝试使用:

  

仓/捆扎

而不是

  

答案 4 :(得分:3)

我遇到了完全相同的问题,并在整个互联网上尝试了所有方法,但最终对我有用的命令是:

gem update --system

答案 5 :(得分:2)

以下是遗产项目对我有用的东西:

  1. 通过rbenv
  2. 设置正确的ruby版本
    
        $ cd YOUR_PROJECT_DIRECTORY
        $ rbenv install 2.1.0
        $ rbenv local 2.1.0
    
    1. 如果在安装捆绑包时仍然出现错误,请查找路径警告:
    2. 
          $ 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
      
      1. 更新你的路径:
      2. 
            $ PATH=/Users/lex/.gem/ruby/2.1.0/bin:$PATH
        
        1. 再试一次:
        2. 
              $ 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/
              . . .
          

          使用sudo来安装gem通常不是你想要做的。

答案 6 :(得分:2)

尝试全局设置ruby

rbenv global 2.3.1

答案 7 :(得分:1)

如果没有其他解决方案对您有用,请尝试此操作。

由于某种原因,我无法在特定的ruby版本上安装捆绑软件,因此重新安装捆绑软件对我没有任何帮助。

但是,我注意到rbenv whence bundle是如何指定该捆绑软件在某些红宝石版本中处于活动状态的,而在其他版本中却不是。如果您查看不带捆扎器的宝石的路径(对我来说是~/.rbenv/versions/2.5.1/bin/),您会发现它不存在。但是,在其他可以识别的版本下,您会看到可执行文件在那里(对我来说,它在~/.rbenv/versions/2.3.1/bin/bundle下)。

只需将可执行文件从工作的ruby版本复制到已损坏的版本即可。然后,在文件顶部,您会注意到sha-bang设置为其他红宝石版本(对我来说,这是#!/Users/myuser/.rbenv/versions/2.3.1/bin/ruby)。将版本路径更改为您要修复的ruby版本,然后它就会神奇地开始工作。

答案 8 :(得分:1)

我今天有一个类似的问题。我的问题已修复如下:

system dependencies
- rvenv
- ruby 2.5.0
- rails 5.1.6
检查Gemfile.lock中的捆绑程序版本
BUNDLED WITH
  1.17.3
安装捆绑软件的特定版本
$ 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

希望这对某人有帮助。

答案 9 :(得分:1)

要安装Ruby小于2.3.0的捆绑程序,请使用以下命令

gem install bundler -v '< 2'

答案 10 :(得分:0)

我有一个与Foreman一起运行Guard的类似问题。 我运行它的原始命令是:

bundle exec foreman run guard -c

这给了我这些错误:

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>'

简单的解决方法是不与工头使用bundle exec,而是将其用于防范。 e.g。

foreman run bundle exec guard -c

希望这有帮助。

答案 11 :(得分:0)

没有一个答案对我有用,因此我必须完全卸载rbenv以及与Ruby相关的所有内容,然后才通过Homebrew安装Ruby 2.7.1; brew install ruby