[Ruby] Your Ruby version is 2.6.3, but your Gemfile specified 2.5.8

Introduction

I got an error in the title when I was touching Ruby, so I wrote it as an article.

Encounter with error

I ran into an error with bundle install while touching an app that was in the process of being created.

$ bundle install
-> Ruby version is 2.6.3, but your Gemfile specified 2.5.8

From the error statement, I can think that the version of Ruby and the version specified by Gemfile are different.

Corresponding

First, let's check the version of Ruby.

$ ruby -v
-> ruby 2.5.8p224 (2020-03-31 revision 67882) [x86_64-darwin19]

Since rbenv is used, check there as well

$ rbenv versions
  system
  2.1.5
  2.5.1
* 2.5.8
  2.6.3
  2.7.1

It looks like it looks right.

Let's check with gem environment where you can refer to the path of Ruby you are using now.

$ gem environment
-> RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.6.2
  - RUBY VERSION: 2.5.8 (2020-03-31 patchlevel 224) [x86_64-darwin19]
  - INSTALLATION DIRECTORY: /Users/username/.rbenv/gems/2.5.0
  - USER INSTALLATION DIRECTORY: /Users/username/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /Users/username/.rbenv/versions/2.5.8/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/username/.rbenv/gems/2.5.0/bin
  - SPEC CACHE DIRECTORY: /Users/username/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/username/.rbenv/versions/2.5.8/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-19
  - GEM PATHS:
     - /Users/username/.rbenv/gems/2.5.0
  - GEM CONFIGURATION:
  ...(Continue)

Well, it looks like it's not wrong ...

The solution

Check the location of the bundle

$ which bundle
-> /usr/local/bin/bundle

Take a look at the contents

-> % cat /usr/local/bin/bundle 

#!/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'bundler' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0.a"

str = ARGV.first
if str
  str = str.b[/\A_(.*)_\z/, 1]
  if str and Gem::Version.correct?(str)
    version = str
    ARGV.shift
  end
end

...(Continue)

Oh, I'm referring to /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby ...

$ which ruby
/Users/username/.rbenv/shims/ruby 

Changed the reference to /Users/username/.rbenv/shims/ruby.

The bundle install has passed successfully!

Reference article

https://qiita.com/h5y1m141@github/items/74029cab9706971c8dbe

Recommended Posts

[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 version error] How to solve Your Ruby version is ~, but your Gemfile specified ~
Behavior when wild card (**) is specified in ruby
The ruby version is managed in the .rbenv / version file
repository The specified gem is bundle installed but not updated to the latest version
I specified the version and rails new, but for some reason the latest version is included ~
[Ruby] What is true?