如何解决'你的 Ruby 版本是 2.6.3,但是你的 Gemfile 指定的是 2.7.4" 怎么办?

How to resolve 'Your Ruby version is 2.6.3, but your Gemfile specified 2.7.4" What should I do?

宝石文件

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.4'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem 'rack-cors'

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

group :development do
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem "active_model_serializers", "~> 0.10.12"
gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master'

在我开始开发一个需要 ruby 版本 2.6.3 的新应用程序之前,我的应用程序运行得非常好,我相信我不小心更改了 ruby 版本。

% rvm list rubies
   ruby-2.6.3 [ missing bin/ruby ]
   ruby-2.7.2 [ x86_64 ]
   ruby-2.7.3 [ x86_64 ]
 * ruby-2.7.4 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

看来我当前的 ruby 版本是 2.7.4,但应用程序显示我的版本是 2.6.3

我收到的错误:

Your Ruby version is 2.6.3, but your Gemfile specified 2.7.4

我试过关注

使用 gemsets 避免意外更改 ruby 版本,但现在使用命令:

rvm use 2.7.4 --default

https://rvm.io/gemsets/creating

在项目中,需要创建一个是gitignore的文件

.ruby-gemset ->
cool_project #project_name

.ruby-version ->
2.7.4 #project ruby version 

之后,每个项目都会有一个迷你环境,不会不小心破坏它。