The version of Ruby that was installed by default on the Mac was referenced, not from rbenv

Difference between rbenv and Ruby version installed by default on Mac

When I tried to start work and did bin / rails s as usual, I got the following message.

$ bin/rails s
Your Ruby version is 2.6.3, but your Gemfile specified 2.6.5

When I check the version of Ruby set in the system, I should have installed 2.6.5 with rbenv, but it is 2.6.3.

$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

I also checked the version specified in rbenv just in case, but there is no mistake in 2.6.5.

$ rbenv versions
  system
* 2.6.5 (set by /Users/username/desktop/Directory name/.ruby-version)
  2.7.0

Check the reference destination of Ruby

First, check if the rbenv path is in place, but there was no problem.

$ cat ~/.bash_profile
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

When I checked the reference destination of the ruby command, it was not referenced from rbenv as shown below. The same was true for the bundler command.

$ which ruby
/usr/local/bin/ruby
$ which bundler
/usr/local/bin/bundler

I also checked the order in which the paths were read, but there was no problem with the reading order. Therefore, I speculated that there might be a problem with the installation status of rbenv in the first place. First, I checked shims of rbenv. shims is a file that manages rbenv's executable commands such as ʻirb, gem, rake, rails, ruby`.

$ ls -l ~/.rbenv/shims
#It was empty.

Because the contents were empty, it was said that the version of Ruby managed by rbenv was not referenced. Was it deleted in some way ...

Install another version of Ruby

At first, I didn't intend to install another version of Ruby, so I ran rehash, which is a function of rbenv, to add a set of commands to shims.

$ rbenv rehash

#Check shims if commands have been added
$ ls -l ~/.rbenv/shims
#Leave empty...

Running rehash did not add any commands. We conducted various investigations, but did not find the cause. At this time, I decided to install Ruby 2.6.6, which is a stable version as of May 26, 2020, when I wrote this article.

Install Ruby 2.6.6

$ rbenv install 2.6.6
$ rbenv rehash  #Add command
$ rbenv global 2.6.6 #Specify the version to be used system-wide

Check the reference destination of the ruby command

$ which ruby
/Users/username/.rbenv/shims/ruby
$ which bundler
/Users/kawafujimasashi/.rbenv/shims/bundler #Check the bundler just in case. It was added without any problems.

Apply the version of Ruby installed on Rails

#Move to the top level directory of your Rails application
$ rbenv local 2.6.6 #Specify the version of Ruby to use.ruby-rewrite the version file
$ bundle install

And when I executed bin / rails s, the version specified by rbenv was referenced and it worked.

Referenced page

Official github README https://github.com/rbenv/rbenv#how-rbenv-hooks-into-your-shell

Recommended Posts

The version of Ruby that was installed by default on the Mac was referenced, not from rbenv
Manage the version of Ruby itself with rbenv
[Ruby] How to use rbenv (version `x.x.x'is not installed)
Manage multiple versions of Ruby on Mac [macOS + rbenv]
What to do if you installed Ruby with rbenv but the version does not change
[Java] The story that the expected array was not obtained by the String.split method.
How to solve the local environment construction of Ruby on Rails (MAC)!
part of the syntax of ruby ​​on rails
The function that can be divided and assigned by right assignment of the development version of Ruby 3.0 has been added.
Ruby from the perspective of other languages
[Ruby on Rails] Implement a pie chart that specifies the percentage of colors
Check the version of the JDK installed and the version of the JDK enabled
[Ruby on Rails] Until the introduction of RSpec
The ruby version is managed in the .rbenv / version file
Install the latest version of Jenkins on Ubuntu 16
Command that the registered information was not found
[Ruby on Rails] Implementation of validation that works only when the conditions are met
Learn the meaning of "passing the PATH" by building a Java development environment on Mac
Library not loaded when trying to upgrade the version of ruby and rails s
[Spring Boot] The story that the bean of the class with ConfigurationProperties annotation was not found
The story that the performance increased by 9.26 times when the layout method of View was changed from AutoLayout to warm hand calculation.
Memo that Azure Functions × Node.js × Typescript was run by Docker on the local virtual environment and debugged from VS Code