[Ruby version error] How to solve Your Ruby version is ~, but your Gemfile specified ~

Introduction

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

Target audience

・ 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."

Purpose

-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")

Premise

-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]")

table of contents

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

1 Error details

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.

2 Try switching the Ruby version.

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 the problem is not solved in 3.2, check the reference destination.

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

3-1 What happens when you execute the 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.

3-2 How to check the execution source file of ruby command

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.

4 Set the ruby command to be executed from the file under rbenv (pass the path)

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!

5 Finally

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

[Ruby version error] How to solve Your Ruby version is ~, but your Gemfile specified ~
[Ruby] Your Ruby version is 2.6.3, but your Gemfile specified 2.5.8
Your Ruby version is 2.4.6, but your Gemfile specified 2.6.4
[Ruby on Rails] How to display error messages
[Rails] How to solve "Uglifier :: Error: Unexpected character'`'"
[Ruby] Meaning of &. How to avoid the error when the receiver (object) is nil
repository The specified gem is bundle installed but not updated to the latest version
[Heroku] How to solve when an error is displayed on git push heroku master
[Ruby] How to use rbenv (version `x.x.x'is not installed)
How to resolve SSL_connect error in PayPal Ruby SDK
How to lower java version
How to use Ruby return
[Ruby] How to comment out
[Ruby] Introduction to Ruby Error statement
Ruby: How to use cookies
[Ruby] How to write blocks
How to check JSF version
How to create your own Controller corresponding to / error with Spring Boot
[For beginners] Ruby is said to be ruby, but what about it?
I get a Ruby version error when I try to start Rails.
Project facet Java version 13 is not supported. How to deal with
How to solve the unknown error when using slf4j in Java
How to install ruby through rbenv
How to use Ruby on Rails
How to install Bootstrap in Ruby
[Ruby] How to use any? Method
How to use Ruby inject method
How to execute Ruby irb (interactive ruby)
[Docker] How to solve the error function not implemented @ io_fread ~ [Super easy]
How to build an environment for any version of Ruby using rbenv
How to solve the local environment construction of Ruby on Rails (MAC)!
[Ruby] How to prevent errors when nil is included in the operation