blue workbench

Ruby and Rails

【Rails】RailsアプリケーションのRubyバージョンを上げる

1. ローカルPCのRubyバージョンを上げる

now-on-air.hatenablog.com

2. アプリケーションの .ruby-version を更新する

$ cd プロジェクトルート
$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
$ rbenv local 2.7.1
$ ruby -v          
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin17]

.ruby-version も更新されます。

3. gemを更新する

$ rails s
rbenv: rails: command not found

The `rails' command exists in these Ruby versions:
  2.3.3
  2.5.1
  2.6.5
  2.7.0

$ gem update --system
Latest version already installed. Done.

→不要かも?

$ gem install bundler
Fetching bundler-2.1.4.gem
Successfully installed bundler-2.1.4
Parsing documentation for bundler-2.1.4
Installing ri documentation for bundler-2.1.4
Done installing documentation for bundler after 3 seconds
1 gem installed

→不要かも?

$ rails s
rbenv: rails: command not found

The `rails' command exists in these Ruby versions:
  2.3.3
  2.5.1
  2.6.5
  2.7.0

$ bundle install
Traceback (most recent call last):
        2: from /Users/y_tsubasa/.rbenv/versions/2.7.1/bin/bundle:23:in `<main>'
        1: from /Users/y_tsubasa/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
/Users/y_tsubasa/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.5) required by your /Users/y_tsubasa/repo/tsubasa-yoshida/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.16.5`

$ bundle update --bundler
Your Ruby version is 2.7.1, but your Gemfile specified 2.5.1

(ここでGemfileのruby 'x.x.x'を修正する)

$ bundle update --bundler

$ bundle install

→不要かも?

$ bundle update

$ rails s
=> Booting Puma
=> Rails 5.2.4.2 application starting in development 
=> Run `rails server -h` for more startup options
/Users/y_tsubasa/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-5.2.4.2/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/y_tsubasa/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-5.2.4.2/lib/action_dispatch/middleware/static.rb:111: warning: The called method `initialize' is defined here
Puma starting in single mode...
* Version 3.12.4 (ruby 2.7.1-p83), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop

参考

qiita.com