In this article, I will write about the solutions to the following errors and why I thought so. In solving it, I referred to the articles and blogs of many people. Links will be posted at any time in the relevant places.
Your Ruby version is 2.6.3, but your Gemfile specified 2.5.1
・ Those who have been learning Ruby for several months to a year. ・ Those who encounter the above error for the first time. ・ "I found out that it seems to be solved by somehow setting the environment variables." "But when I hear the words vim and shell, I want to take a breath before solving it."
-Operate vim to pass the PATH (hereinafter referred to simply as "path") to the file under rbenv and resolve the version error.
・ Understand why passing the path solves the problem.
What is an environment variable to pass through Path
[IT term "Path" that makes you feel "understood" even if you "understand" and "do not understand"] (https://wa3.i-3-i.info/word1166.html "IT term" Path "that makes you feel like you understand even if you don't understand")
-Rbenv (ruby version control tool) is already installed.
-It has been confirmed that the ruby version you want to change (2.5.1 in this case) is installed.
[Use ruby with rbenv [zsh]] (https://qiita.com/itsmedachan/items/b86a124aec5a55b375e8 "Use ruby with rbenv [zsh]")
1 Error details
2 Try switching Ruby versions
3 If the problem is not solved in 2, check the ruby reference destination. 3-1 What happens when you execute the ruby command 3-2 How to check the execution source file of ruby command
4 Set the ruby command to be executed from the file under rbenv (pass the path)
5 Finally
The details of the error are here.
Your Ruby version is 2.6.3, but your Gemfile specified 2.5.1
The meaning of the error is "The version of Ruby in your PC environment is 2.6.3." "But the Ruby version of the application you are currently developing is 2.5.1." That is.
Follow the steps below to try switching versions. -Check the Ruby version. -Use rbenv to switch versions. ・ Check if the switch has been made.
(1) Check the version of Ruby in your PC environment.
ruby -v
(2) Check the version of Ruby applied to the application under development.
rbenv -v
(3) Try to change the version using rbenv.
When specifying the version of Ruby to use in a particular directory.
rbenv local 2.6.3
When specifying the version of Ruby to be used for the entire system.
rbenv global 2.6.3
(4) Check if the Ruby version has been switched.
ruby -v
ruby 2.6.3p645 (〜)... //Output result
It didn't switch.
If it does not switch by the above method, the reference destination when executing the ruby command may be different.
[What to do when the Ruby version does not switch! ] (https://qiita.com/opiyo_taku/items/3312a75d5916f6cd32b1 "What to do when the Ruby version does not switch!")
In this article, we will consider the cause of the error and why it can be resolved. Therefore, it will be explained in the following flow.
3-1 What happens when you execute the ruby command 3-2 How to check the execution source file of ruby command
The PC we have has a lot of files that contain all the commands.
[What is an environment variable to pass through Path] (https://qiita.com/fuwamaki/items/3d8af42cf7abee760a81 "Passing Path is an environment variable")
For example, when we are typing a command on the terminal. In the PC, find the file that contains the command entered in the terminal from among many files, extract the command from it, and execute it.
The ruby command is the same.
However, there may not be one file that contains the ruby command. What this means is that if you install rbenv like this time, -Files under rbenv created at the time of installation ・ Files originally on the PC It means that both of them may contain the ruby command.
In this case, -File under rbenv-> 2.5.1 version of ruby command is included. -File originally in the PC → 2.6.3 version of ruby command is included. It means that the situation can be considered.
Now, let's actually check "If you type the ruby command, what file is the ruby command in?" Use the which command to see the reference.
which ruby
usr/bin/ruby //Output result
This output result is "By executing the ruby command, execute the ruby command in the file under usr" It means that · · ·
If ruby version control is performed by rbenv, the ruby command is also included in the file under rbenv. If the ruby command is executed, the output result will be as follows.
/Users/you/.rbenv/shims/ruby
I referred to this article for the reason why it has such a configuration. [Role of rbenv] (https://qiita.com/souichirou/items/d4196faa0df9e4bacf17 "Role of rbenv")
To quote a part of the article, When installing rbenv
~ / .rbenv / (root folder)
~ / .rbenv / shims / (folder to save wrappers for commands installed by ruby and gem)
Etc. will enter the PC. The ruby command you want to execute is stored in this shims folder.
Set the PC to bring the ruby command from "/Users/you/.rbenv/shims/ruby" instead of "usr / bin / ruby".
The following articles were used as a reference.
[What you are doing with "pass through" (macOS / zsh)] (https://knmts.com/become-engineer-2/ "What you're doing with" passing the path "(macOS / zsh)")
Here, we will write the following procedure. ・ Open vim -Write the code, save and exit. ・ Reflect the changes.
(1) Open vim with the following command. (If you are using bash in your shell, please replace ".zshrc" with ".bash_profile".)
vim ~/.zshrc
(2) Press i to make it editable. Nothing changes on the screen, but you can add and edit.
(3) Write the following code. If it is already mentioned, write it on the line below it.
export PATH="~/.rbenv/shims:/usr/local/bin:$PATH"
eval "$(rbenv init -)"
(4) Press esc to make it possible to save and exit. I think the cursor will move to the bottom. (5) Type: wq and press enter. (6) The screen will return to the original screen, so type the following command. The source command is a command that reflects the changes.
source ~/.zshrc
(7) Check the ruby version.
ruby -v
ruby 2.5.1p645 (〜)... //Output result
It went well!
If you find any mistakes or typographical errors in the content of the article, please let us know in the comments.
Thank you to the authors of the articles and blogs for reference and citation.
Recommended Posts