从 Rails 上的 Ruby 4.2.7.1 升级到 5.0.1——仍然尝试使用 railties 4.2.7.1

Upgrading from Ruby on Rails 4.2.7.1 to 5.0.1 -- still tries to use railties 4.2.7.1

我正在创建一个网站,但不小心在 Rails 版本 4 而不是版本 5 上安装了 Ruby,我想升级到最新版本以使用一些功能我系统上的版本目前缺少这些。

我已尝试遵循此指南:

http://railsapps.github.io/updating-rails.html

我按顺序安装了 rvm 和 运行 所有预备程序,直到这一部分:

rvm use ruby-2.3.1@rails5.0 --create
gem install rails
rails -v

我运行哪里出问题了。 rvm use ruby-2.3.1@rails5.0 --create 输出:

ruby-2.3.1 - #gemset created /home/dev/.rvm/gems/ruby-2.3.1@rails5.0
ruby-2.3.1 - #generating rails5.0 wrappers..........
Using /home/dev/.rvm/gems/ruby-2.3.1 with gemset rails5.0

很好。 Gem install rails 也没有错误地继续安装所有 36 个 gem,包括,至关重要的是:

Fetching: rails-5.0.1.gem (100%)
Successfully installed rails-5.0.1

Fetching: railties-5.0.1.gem (100%)
Successfully installed railties-5.0.1

然而,当我直接 运行 rails -v 之后,我得到:

Could not find proper version of railties (4.2.7.1) in any of the sources  
Run `bundle install` to install missing gems.

当我运行 bundle install,然而,系统恢复到rails 4.2.7.1。

我是否需要对 install/link/whatever railties 4.2.7.1 做一些额外的事情,并阻止系统恢复到 rails 的原始版本?我不怎么用rails所以对配置不是特别熟悉。也许我需要更改我的应用程序中的配置文件?

问题出在包含旧版本号的 Gemfile 中。我更新为以下内容:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.1'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.13', '< 0.5'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.6'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 3.0.4'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2.1'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.4.1'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.1', group: :doc

# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

然后是 运行 bundle update 然后是 bundle install 现在有 Rails 5.0.1。感谢 Iceman 建议查看 Gemfile!