Home > database >  Fix Your Ruby version is 2.6.8, but your gemfile specified 2.5.5
Fix Your Ruby version is 2.6.8, but your gemfile specified 2.5.5

Time:03-09

On my local machine I'm using rbenv

When I run bundle install I get:

The git source `git://github.com/sinatra/sinatra.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
Warning: the running version of Bundler (1.17.2) is older than the version that created the lockfile (1.17.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
Following files may not be writable, so sudo is needed:
  /Library/Ruby/Gems/2.6.0
  /Library/Ruby/Gems/2.6.0/build_info
  /Library/Ruby/Gems/2.6.0/cache
  /Library/Ruby/Gems/2.6.0/doc
  /Library/Ruby/Gems/2.6.0/extensions
  /Library/Ruby/Gems/2.6.0/gems
  /Library/Ruby/Gems/2.6.0/specifications
Your Ruby version is 2.6.8, but your Gemfile specified 2.5.5

The problem is, when I run rbenv versions, I get the right version (2.5.5):

  system
* 2.5.5 (set by /Users/Mahmoud/dev-reps/non-docker/normal/.ruby-version)

And when I run which ruby, it correctly points to rbenv:

/Users/Mahmoud/.rbenv/shims/ruby

Even ruby -v gives the correct version:

ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin21]

So persumably, 2.5.5 is the ONLY version I have. In addition to this I tried all the usual hacks related to bundler:

bundle uninstall, gem uninstall bundler -v 1.17.2 but nothing seems to work.

Another "interesting" fact that I think gives a hint: which bundle gives:

/usr/local/bin/bundle

My question is where is this 2.6.8 coming from? And how can I fix this and start the server?

CodePudding user response:

Finally got it working.

So the key to the problem as well to the solution was the fact that which bundle gave:

/usr/local/bin/bundle

while which ruby gave:

/Users/Mahmoud/.rbenv/shims/ruby

indicating that bundle isn't using ruby from rbenv.

I already had the path set in ~/.bash_profile:

export PATH="$HOME/.rbenv/shims:$PATH"
eval "$(rbenv init -)"

but apparently this was not enough as I was using zsh. Had to add those same 2 lines to ~/.zshrc as well and restarted terminal. Now bundle install is working as expected.

After updating ~/.zshrc which bundle gives:

/Users/Mahmoud/.rbenv/shims/bundle

indicating that the problem was just that bundle was using the wrong ruby.

So if you have this problem, just make sure ~/.bash_profile and ~/.zshrc have the correct path by adding the 2 lines indicated above. Restart terminal and check if its working now.

  • Related