Get on my level: How to get your computer and gemfile on the same Ruby version
Imagine working on your project for a few days, taking a break, and coming back to a console and server that no longer run. After some mild hyperventilating, you start to follow the suggestions Rails gives you, install [this], update [that], bundle lock [that other thing], but nothing. That was me this morning! To be honest I can’t even remember what the original error was but after blindly following Rails’ instructions for a longer time than I want to admit I turned to the internet.
The error from above is where I started my search. I’m not quite sure how I ended up with an older bundler than the one that created my lockfile or with a different version of Ruby but I’m sure it had to do with blindly following suggestions. I was tired of ‘solving’ this problem so I figured an easy solution would be to change the Ruby version in my gem file from 2.7.1 to 2.7.0 and bundle install. I was wrong!
My next message was about fallbacks possibly breaking my app. I don’t know about you but anytime the words break and app are in the same sentence I freak out. I now know that this deals with the fallback behavior/languages in case of a missing translation, but at the time I was pretty scared! For the current version of I18n, your fallback configuration should be config.i18n.fallbacks = [I18n.default_locale]
instead of config.i18n.fallbacks = true
.
After another bundle install I got almost the same error as the first, Your Ruby version is 2.6.1, but your Gemfile specified 2.7.0
. Remember how I thought changing the last number and bundle installing would fix my issue?
In order to solve this I used RVM, a command-line tool which allows the manipulation of multiple ruby environments. I already had the ruby version I wanted installed, but if you don’t, install it by typing in $ rvm install ruby_version_you_want
. From here you can view what version(s) you have installed by typing in $ rvm list
. If the Ruby version you want as your default is not selected, you can change it by typing in $ rvm --default use ruby_version_you_want
. This should fix the issue, but you can always double check that it worked by typing in either $ rvm current
or $ ruby -v
.
Lastly, I had to update my bundler. That was quick fix with gem install bundler:2.1.4
(gem update bundler
can also be used). I’ve been pretty lucky that I have not had any issues with my environment since I initially set it up and I took it for granted. Today was a great reminder to not follow prompts blindly, take shortcuts to avoid solving the real issue, and always search what you don’t fully understand.