Search code examples
ruby-on-railsrubyrvmbundlerrbenv

Rbenv not using the correct version


In my rails project, when I try to run bundle install, I get the following error:

Your Ruby version is 2.3.7, but your Gemfile specified 2.5.3

However, when I run ruby --version I get:

ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]

...and running rbenv version gives me:

2.5.3 (set by /Users/jamesmulholland/proj/repo-name/.ruby-version)

What is cauing this the wrong version of Ruby to be used here, and how do I fix it?


Other Context and Failed Fixes

  • Running rbenv versions gives: system 2.5.3 (set by /Users/jamesmulholland/proj/repo-name/.ruby-version)`

  • This issue has occurred during a move from Ruby 2.5.1 to Ruby 2.5.3. At the same time, I moved from rvm to rbenv. I suspect I may have uninstalled rvm incorrectly as I ran rm -rf ~/.rvm rather than rvm implode but /etc/rbenv/ is empty and running rvm commands fails. rvm is removed from my .zshrc. When I continued to run into this issue after this method of uninstalling rvm, I reinstalled rvm and uninstalled using the rvm implode process in case there were any other traces of rvm left that were causing issues. This also failed to fix the issue.

  • I completely removed the directory and pulled a fresh copy from GitHub. No success.
  • Checking out an old commit does not fix the error (I get Your Ruby version is 2.3.7, but your Gemfile specified 2.5.1 instead)
  • The application runs fine on my colleague's computer.
  • Potentially relevant section of my .zshrc (the rvm equivalent is commented out): export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)"
  • .ruby-version is 2.5.3
  • Gemfile contains: source 'https://rubygems.org' ruby "2.5.3"

Solution

  • Try with this.

    In your rails project folder check the presence of .ruby-version file and put inside the same ruby version specified into Gemfile. (if this file is not present, create it.)

    ~/your-rails-project/.ruby-version file:

    2.5.3
    

    ~/your-rails-project/Gemfile file:

    source 'https://rubygems.org'
    ruby '2.5.3'
    ...
    

    Then install that version with rbenv:

    $ rbenv install 2.5.3
    $ rbenv rehash
    $ rbenv local 2.5.3
    $ rbenv global 2.5.3
    

    Now check that you are using the right version with:

    $ ruby -v