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
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 ...
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.
$ rbenv install 2.6.6
$ rbenv rehash #Add command
$ rbenv global 2.6.6 #Specify the version to be used system-wide
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.
#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.
Official github README https://github.com/rbenv/rbenv#how-rbenv-hooks-into-your-shell
Recommended Posts