sudo bundle 导致“找不到捆绑器”错误

sudo bundle causes `could not find bundler` error

我有 bundle exec 工作正常,但是当我尝试执行 sudo bundle exec 时,我有 Could not find 'bundler' (>= 0) 错误。

这是完整的错误信息。

smcho@macho appname> sudo bundle exec unicorn -c config/unicorn.rb -E production -D
/Users/smcho/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'bundler' (>= 0) among 11 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/smcho/.gem/ruby/2.2.0:/Users/smcho/.rvm/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0', execute `gem env` for more information
    from /Users/smcho/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
    from /Users/smcho/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
    from /Users/smcho/.rvm/gems/ruby-2.2.3/bin/bundle:22:in `<main>'
    from /Users/smcho/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
    from /Users/smcho/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'

我发现很多 questions/answers 与此问题相关,但似乎没有任何效果。

为了使用bundle命令,您需要先安装bundler

sudo gem install bundler

然后你就可以使用bundle命令:

sudo bundle exec . . .

查看 bundler official page 了解更多信息。