Commands to keep your app healthy, Ruby and Rails and gems wise using RVM.
If you use rbenv, please see Rails-application-health-codes-rbenv.md
Open new Terminal, note the gemsets showing:
rvm gemset list
You will see you are using the (default) gemset.
Keep your system up to date with rvm
and brew
:
rvm get head
brew update
: will update your Homebrew (takes a while):
brew doctor
: check to make sure all is well
rvm list known
: Ref : Rubies rvm knows about and can install
The part I am most interested in this day in June 2021 reads as:
...
[ruby-]2.5[.9]
[ruby-]2.6[.7]
[ruby-]2.7[.3]
[ruby-]3[.0.1]
ruby-head
Which version of Ruby to use with which version of Rails ??
Rubygems Rails Versions
Click on your version, and check its requirements.
Now, check your ruby version, just so you know,
upgrading command comes later, make no change to ruby yet.
ruby -v
Run these:
rvm gemset list
: we want to use global
rvm gemset use global
gem update --system
gem update rake
gem update bundler
gem update rubygems-bundler
gem outdated
A VALID NOTE from stackoverflow
"Don't ever use 'bundle update' or 'gem update' arbitrarily. That's like saying
"give me the newest versions of all gems from all available sources" without knowing
the effects beforehand. It can be a Pandora's Box of trouble if you aren't careful,
especially 'bundle update'."
The solution to this problem causer is to update gems one at a time, and run tests.
This method lets you easily check each Gem's upgrades as you go along, and prevents
your being overwhelmed with breaks in your app. When you have tests in place covering
your code, finding the causes of those breaks becomes easy peasy lemon squeezey.
EXAMPLE:
bundle update selenium-webdriver
: and then run your tests, to check.
bundle update launchy
: and then run tests that use Launchy, to check.
Because we are in the => global gemset, I always do the gem update.
Verify with:
rvm gemset list
gem update
: updates only the global gemset gems
Now we install Ruby ..
rvm install 2.6.7
: adjust to desired version.
Our @global gemset now contains Ruby 2.6.7, a Heroku supported version. Both these commands are the same, run one:
rvm use ruby-2.6.7
rvm use 2.6.7
If you want to use 2.6.7 from now on, use:
rvm --default use ruby-2.6.7
We have a new @global entity, Ruby 2.6.7,
and it needs a few things to make it sing.
Now we install Rails into this new ruby container.
We are in the global
gemset. How do you know ??
Run ..
rvm gemset list
gem install rails -v 6.1.4
The global gemset now contains Ruby 2.6.7 with Rails 6.1.4
To better underdstand this process
I refer you to these instructions:
Rails <=> Ruby Verisions
Now we add into the Ruby 2.6.7 container its new bundler:
gem install bundler
Take a breath before we change into you app's directory.
We are going to be making changes to add the new Ruby and Rails
to the app.
Change Directory the app ..
cd your_application_name
rvm gemset list
: still on => global
Now, I will make a new feature branch, and the reason is,
upgrading from Rails 5 to Rails 6 is a major leap, entailing many
changes.
The git branch
command will show you where you are.
I have two branches, master and staging, perfect mirrors.
git branch
master
* staging
I am in the staging branch.
I make the new branch:
git checkout -b rails60to61
Rails 6.0.3.1 to 6.1.4
I read the changes for each version, and all will be well.
Now ..
open -e Gemfile
: change Ruby and Rails version
open -e .ruby-version
: change Ruby version
open -e .ruby-gemset
: change to new gemset name you create below
We are still using global gemset.
We now create new gemset for the app, for first time creation use:
rvm gemset use Rails6.1.4_your_app_name --create --default
With above command used once, below is never needed:
rvm gemset use Rails6.1.4_your_app_name
Run this command again, you will see the gemset is being used:
rvm gemset list
You just created and are now using the application's gemset.
The --default
switch will cause this gemset to be used when
you first enter the app directory. At this point, I personally
like to close that terminal window and open a new one, and watch
the rvm magic show itself as it recognizes the new gemset.
If you ever change gemsets, the use
command is the way back.
However, at this point, when you change directory into this app,
the .ruby-gemset
file will be used to set the correct gemset.
You can use the command to change gemsets and change back:
rvm gemset use Rails5.0.0_your_app_name
rvm gemset use Rails6.1.4_your_app_name
To upgrade your rails version, install Rails wtih this:
gem install rails --version 6.1.4
If all is well on rails response, skip down to
bundle update rails
below.
Otherwise do this:
open -e Gemfile
: to change Rails version to new version then run
gem install rails
: If all is not well, check your gemset with:
rvm gemset list
: decipher the terminal response.
If you see an error such as:
Ignoring executable-hooks-1.3.2 because its extensions are not built.
Try: gem pristine executable-hooks --version x.x.x
DO NOT DO the Try suggestion.
It means you are in the default or global gemset or you have a brand new gemset.
Verify your app's gemset with:
rvm gemset list
Changing gemset will work if you are in wrong one.
You want to be here: Rails6.1.4_your_app_name
You get there by running this, anytime:
rvm gemset use Rails6.1.4_your_app_name
Now run:
gem install rails
The response is:
Successfully installed rails-6.1.4
1 gem installed
Now run:
bundle update rails
Now run:
bundle install
Now we update Rails and it is important to do this every time you upgrade Rails versions.
The Rails command is:
rails app:update
If the process asks you if you want to overwrite a file, type in
d
for diff
and it will show you the changes it is about to make.
If you have working code in your file that cannot be overwritten,
and yet there is new code to be added, simply open the file it wants to overwrite,
and make those additions by hand, save the file, close it,
and choose n
: do not allow the overwrite. That preserves your code and adds new.
An example is if you are using the Spring gem, you will see codes with /spring/ in the
bin file overwrite question, after you type in d
for diff
, you will know what to do.
Do not allow overwrite of spring codes in the bin/files if you need to make additions.
Now, do we have any outdated gems ?
This is a safe command, changing nothing:
bundle outdated
Next command is not a safe one, possibly updating many gems,
changing many things:
See A VALID NOTE above, and note here below before running bundle update
Run bundle outdated
before you blindly run the following update command.
You can see how many gems will be updated if all are done with one command.
You can update gems one by one with bundle update gem_name
Recommend you do a git commit
command before you run this
updates-all-gems-command, if you have many gems outdated.
bundle update
ruby -v
rails -v
gem list
: shows you all gems in your new gemset
Choose your correct gemset for your app, if you have more than one.
Let us presume this is your first gemset ..
We will create a good name for it : Rails6.0.3_your_app_name
Yes, change the app_name to your app's name for easy reference.
If you have an app that uses Rails5.1, you can revert to the Rails5.1
gemset should the need arise.
Your app is now ready to go.
At any time you can do the steps above to keep your app humming.
As needed to be current, make appropriate changes here:
open -e .ruby-gemset
open -e .ruby-version
bundle install
Fire it up with:
rails s
If you ever lose track of where you are, commands wise, just type into your Terminal:
history
history -10
pwd
print working directory to see where you are
Your app is now updated, Ruby, Rails and gems wise.
Welcome to the your working versions of Ruby on Rails.
Your Rails app's health brought to you by
This list draws heavily upon my learnings with RailsApps Tutorials.
Address of This Rails Applications Health Codes Gist is :
https://gist.github.com/kathyonu/c9ef8190e50422bc0edc