bundle uses wrong ruby version

Linus picture Linus · Oct 30, 2015 · Viewed 12.2k times · Source

I'm trying to run

env RAILS_ENV=test bundle exec rake db:migrate

and get the following error

Your Ruby version is 2.1.7, but your Gemfile specified 2.2.3

ruby -v

gives me

ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]

I'm using rbenv, if that matters. rbenv versions gives the following: system * 2.2.3 (set by /Users/thatsme/Projects/demoproject/.ruby-version) So I have no ruby 2.1.7 installed. Spring is not running and I've run rbenv rehash. Then bundler gem is installed. I'm going nuts on this. Can somebody please tell me why the wrong ruby version is being used? Thanks!

Answer

kev picture kev · Jan 29, 2017

Assumption: You are using RVM. This means there's a ruby version installed outside of RVM. Clear your rvm rubies by running

rvm uninstall <ruby version>

once you have uninstalled all rvm rubies do ruby -v, if this returns an output specifying a ruby version then thats the root of the problem. Uninstall it with

sudo apt-get remove ruby

Now install your rvm rubies with rvm install <ruby version> and set it as default rvm use <ruby version>

Now install bundler

gem install bundler

And do bundle install