One day when I tried to start Rails, I got the following error:
[\W staff@term]rails s
Your Ruby version is 2.6.3, but your Gemfile specified 2.5.1
Ruby will be the modified version.
item | Contents |
---|---|
OS.Catalina | v10.15.4 |
Ruby | v2.5.1 |
Ruby On Rails | v5.2.4.3 |
** Correspondence 1) Check the installable version and install the specified version. ** **
[\W staff@term]rbenv install --list
2.5.8
2.6.6
2.7.1
(abridgement)
[\W staff@term]rbenv install 2.5.1
** Correspondence 2) Switch ruby version **
cmd>rbenv local 2.5.1
[\W staff@term]sudo rbenv versions
system
2.3.1
* 2.5.1 (set by /Users/ichikawadaisuke/projects/krown/.ruby-version)
2.6.3
Even though it has changed as above ...
[\W staff@term]rails s
Your Ruby version is 2.6.3, but your Gemfile specified 2.5.1
[\W staff@term]ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
why. The main subject is from here.
** Correspondence 3) Change the reference destination of ruby. ** **
[\W staff@term]which ruby
/usr/bin/ruby
CMD>export PATH="~/.rbenv/shims:/usr/local/bin:$PATH"
I have confirmed that the environment variables have been changed.
[\W staff@term]env
PATH=/Users/ichikawadaisuke/.rbenv/shims:~/.rbenv/shims:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
Finally, reset the ruby environment.
CMD>eval "$(rbenv init -)"
It was changed as follows, and rails could be started.
[\W staff@term]which ruby
/Users/ichikawadaisuke/.rbenv/shims/ruby
[\W staff@term]ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin19]
[\W staff@term]
This completes the response.