user3063045 user3063045 - 26 days ago 10
Ruby Question

Rails Seeing Incorrect Ruby Version

I've built a Rails 5 app and it's working great but I'd like to change the Ruby version I'm running it on. I'm using RVM 1.27.0 on Ubuntu 16.04. I copied the app folder to a different path and changed the versions on .ruby_version and my Gemfile:

Gemfile:

source 'https://rubygems.org'
ruby "2.2.2"


.ruby_version:

ruby-2.2.2


Once I updated these I moved out and back into the folder and ran a ruby -v:

ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]


I then ran a bundle install and everything installed without error.

However, when I ran rake -T I get this:

Your Ruby version is 2.3.1, but your Gemfile specified 2.2.2.


My $PATH looks good:

/home/ken/.rvm/gems/ruby-2.2.2/bin:/home/ken/.rvm/gems/ruby-2.2.2@global/bin:/home/ken/.rvm/rubies/ruby-2.2.2/bin:/home/ken/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin


What am I missing? Where is Rails pulling the Ruby version from? How can I fix this?

Answer

You're using a system bundler which is why you're seeing a different version of ruby. All you need to do is install bundler under your current ruby version:

gem install bundler
bundle install

Once you do a bundle install you'll get the gem's built for the correct ruby version.