首页 > 解决方案 > Rails 升级抱怨旧的捆绑器版本

问题描述

我想从 Rails 4.2 升级到 6。我已经更新了我的 Gemfile 以包含

fail "run 'gem install bundler' to update your bundler version" unless Bundler::VERSION >= '2.0.0'
source 'https://rubygems.org'
ruby '~> 2.7.1'

gem 'rails', '~> 6.0.0'

但是尝试升级 rails gem 会导致

$ bundle update rails
Traceback (most recent call last):
    4: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:22:in `<main>'
    3: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:22:in `eval'
    2: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/bundle:23:in `<main>'
    1: from /Users/myusername/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
/Users/myusername/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.17.3) required by your /Users/myusername/myrailsapp/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.17.3`

When I try and update the bundler, I get

$ bundle update --bundler
Fetching https://github.com/mimemagicrb/mimemagic.git
Fetching gem metadata from https://rubygems.org/.......
You have requested:
  rails ~> 6.0.0

The bundle currently has rails locked at 4.2.10.
Try running `bundle update rails`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

正如您所料,运行“捆绑更新”也会导致错误……</p>

$ bundle update
Traceback (most recent call last):
    4: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:22:in `<main>'
    3: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:22:in `eval'
    2: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/bundle:23:in `<main>'
    1: from /Users/myusername/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
/Users/myusername/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.17.3) required by your /Users/myusername/myrailsapp/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.17.3`

不知道从这里可以去哪里。

标签: ruby-on-railsruby-on-rails-4upgradebundlerruby-on-rails-6

解决方案


推荐阅读