Ruby-on-Rails: Cannot set correct Ruby Version

Viewed 73

Dearest Community.

Here's an odd one, and I cannot figure this one out myself.

I am about to deploy a Ruby-on-Rails app to a production server. I like to keep all versions consistent between development and production as you do.

In my Gemfile I set the Ruby version to 2.7.1 (correctly), and on development I installed 2.7.1 and use that version locally for this specific project. All works just fine! - here's the entry:

Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
...

The Problem:

On production I installed and use (via rbenv) ruby 2.7.1. And I verified that the version is installed & in use! However, when it try to migrate my database or do any other task for that matter it outputs the following

Your Ruby version is 2.7.0, but your Gemfile specified 2.7.1

I do not even have 2.7.0 installed. So for the sake of it I edited the Gemfile on production to run the test. For the purpose of the test I set the ruby verions to 2.7.0 and run another command that fires up the rack. Now the message is:

Your Ruby version is 2.7.1, but your Gemfile specified 2.7.0

What is happening?! I have never ever had or saw a similar issue before. Any help is much appreciated! Thank you!

Here are the environment details:

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"

ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]

$ rails -v
Rails 6.0.3.2

$ bundle -v
Bundler version 2.1.4
1 Answers

I find the best solution is to uninstall all versions of ruby from your ruby version manager (not familiar with rbenv, but you should be able to listed all installed versions then one by one uninstall the ones you don't need until only the one you need remains. If you need multiple versions, best setup a script that will let you quickly switch or setup isolated development environments (basically virtual machines), such that you can be sure it only has the version it needs.

After that, it will either work fine or you'll have an error message that might help pin down the root cause of the issue.

Related