I get a Ruby version error when I try to start Rails.

background </ font>

One day when I tried to start Rails, I got the following error:

[\W [email protected]]rails s
Your Ruby version is 2.6.3, but your Gemfile specified 2.5.1

environment </ font>

Ruby will be the modified version.

item Contents
OS.Catalina v10.15.4
Ruby v2.5.1
Ruby On Rails v5.2.4.3

Contents </ font>

** Correspondence 1) Check the installable version and install the specified version. ** **

[\W [email protected]]rbenv install --list
[\W [email protected]]rbenv install 2.5.1

** Correspondence 2) Switch ruby version ** cmd>rbenv local 2.5.1

[\W [email protected]]sudo rbenv versions    
* 2.5.1 (set by /Users/ichikawadaisuke/projects/krown/.ruby-version)

Even though it has changed as above ...

[\W [email protected]]rails s
Your Ruby version is 2.6.3, but your Gemfile specified 2.5.1
[\W [email protected]]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. ** **

  • Be sure to make a note of the result with the env command before executing it.
[\W [email protected]]which ruby

CMD>export PATH="~/.rbenv/shims:/usr/local/bin:$PATH"

I have confirmed that the environment variables have been changed.

[\W [email protected]]env

Finally, reset the ruby environment. CMD>eval "$(rbenv init -)"

It was changed as follows, and rails could be started.

[\W [email protected]]which ruby            
[\W [email protected]]ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin19]
[\W [email protected]]

This completes the response.

Recommended Posts