Skip to content

Instantly share code, notes, and snippets.

@kathyonu
Last active February 17, 2025 21:20
Show Gist options
  • Save kathyonu/c9ef8190e50422bc0edc to your computer and use it in GitHub Desktop.
Save kathyonu/c9ef8190e50422bc0edc to your computer and use it in GitHub Desktop.
Rails Applications Upgrade Steps for Ruby, Rails and Gems

Commands to keep your app healthy, Ruby and Rails gems wise.
Each command is described further below.
Open new Terminal:

rvm get stable
brew update
brew doctor
rvm list known
ruby -v
rvm gemset list
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 better learn each Gem 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. EXAMPLE: bundle update launchy and then run tests that use Launchy, to check.

gem update
rvm list known
rvm install 2.4.1
pwd
cd your_application_name
rvm gemset list
open -e Gemfile : change Ruby version
open -e .ruby-version : change Ruby version
open -e .ruby-gemset : change Ruby version
rvm use 2.4.1

Before you upgrade to Ruby 2.4.1, see: Behavior Changes in Ruby 2.4

We are still using global gemset, so now we create new gemset for the app for first time creation use:
rvm gemset use Rails4.2_your_app_name --create --default

Normal useage commands:
rvm gemset list rvm gemset use Rails4.2_your_app_name
ruby -v
rails -v
To upgrade your rails version, do this:
open -e Gemfile Change Rails version to upgrade
gem install rails --version 4.2.10

Continuing, no matter your Rails version or gem install: bundle update rails
bundle install
rake rails:update
bundle outdated

See A VALID NOTE above.

bundle update
rake rails:update:bin
ruby -v
rails -v
gem list

Before you push to production, check your Gemfile.lock for vulnerabilites: Is It Vulnerable ?

Explanations :

#rvm get stable updates your rvm:

rvm get stable

#brew update will update your Homebrew (takes a while):

brew update

#brew doctor will tell you all is well with your Homebrew (takes a while):

brew doctor

#rvm list known will show you the Rubies rvm knows about and can install.
If you do not see Ruby 2.4.1 in the list, we will cover what to do further below.
rvm list known

#pwd will show you what directory you are in:

pwd

Change into your working directory:

cd your-application-name

Check your Ruby version. Expect version to be 2.4.1 or later:

ruby -v

Check your Rails version. Expect version to be 4.2.10 or 5.0 or later:

rails -v

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 : Rails4.2_app_name
Yes, change the _app_name to your app's name for easy reference.
For the first time use, we will add the create and default switches.

rvm gemset use [email protected]_app_name --create --default

Run the prior 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:

rvm gemset use Rails4.2_app_name

You can use the command to change gemsets and change back:

rvm gemset use Rails4.2_app_name
rvm gemset use Rails5_app_name

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

Before you push to production, check your Gemfile.lock for vulnerabilites:

Is It Vulnerable ?

INSTRUCTIONS :

Use the global gemset for this part.
rvm gemset list

You can now see the global gemset exists, now we use it.
rvm gemset use global

You are now using the global gemset, run the list command again,
you will see it is so.
rvm gemset list

Now we begin the updates :

#gem update --system does what it says, updates your system
gem update --system

#gem update rake does what it says, updates your rake gem
gem update rake

#gem update bundler does what it says, updates your bundler gem
gem update bundler

#gem update rubygems-bundler updates your rubygems-bundler gem
gem update rubygems-bundler

#gem outdated checks global gemset for out of date gems
gem outdated

See A VALID NOTE above.

#gem update will update the global gemset
gem update

Update work is now complete using the global gemset.
Next step is to make sure you are in your working directory ..
#pwd will show you what directory you are in.
pwd

Change into your app directory.
cd my_application_name

Now, we look for and change to the gemset the application is using.
rvm gemset list

Choose your correct gemset for your app, if you have more than one.
If that gemset does not exist in the list, what i do is this :
Make sure the Gemfile shows Ruby at 2.4.1
Make sure the .ruby-version file shows 2.4.1
You can use the open -e file-address command at the terminal_prompt.

open -e Gemfile : add the current version of Rails, we are using 4.2.10
open -e .ruby-version : currently it reads as 2.4.1p111
open -e .ruby-gemset : currently reads as Rails-4_2_app_name

Make sure the .ruby-gemset file reads as your real app-gemset-name.
Further below, we will be giving the gemset the name of, Rails4.2_app_name.

#ruby -v will respond with your Ruby version.
ruby -v

If the response is not 2.4.1, tell rvm to use Ruby-2.4.1
rvm use 2.4.1

If the response is not, You are now using Ruby 2.4.1, run
#rvm list known to show you what rubies rvm knows about.

rvm list known

If the 2.4.1 Ruby is not showing, run this lovely command.
rvm install 2.4.1

Watch for rvm install instructions, if any, and use them.
Voila, you are now on Ruby 2.4.1 and yes, it is that easy.
*Now that you are using 2.4.1 we can create the gemset. *
rvm gemset use Rails4.2_app_name --create --default

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 this is the first time you set it.

*If you ever change gemsets, this 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.)
rvm gemset use Rails4.2_app_name

Check your Ruby version. Expect version to be 2.4.1
ruby -v

Check your Rails version. Expect version to be 4.2.10
rails -v

If you are not yet using Rails4.2.10, this is the point that you do so.
gem install rails

Notice it is not, bundle install here, we use gem install.

Make sure you do not skip this next step.
bundle update rails

Now we let Bundler do its work of installing all the requisite gems, and dependencies.
bundle install

If you have difficulties here, trash your Gemfile.lock file, then run the
bundle install command again.

Next we update Rails and it is important to do this every time you upgrade Rails versions.
rake rails:update

If the process asks you if you want to overwrite a file, type in 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 diff : do not allow overwrite of spring codes in the bin/files.

Now is a good time to update your bundled gems.
#bundle outdated will show you all outdated gems in the gemset you are using.
bundle outdated

See A VALID NOTE above.

#bundle update will update your gems.
bundle update

Bundler now does its magic.
Follow any instructions bundler gives you while it updates.

#rake rails:update:bin will update your bin/bundle, bin/rails and bin/rake files.
rake rails:update:bin

*Now check your Rails version, it should read 4.2.10 *
rails -v

*Your Ruby version should read as 2.4.1 *
ruby -v

Your app is now updated, Ruby, Rails and gems wise
Welcome to the Near Edge of Ruby on Rails

Three cheers for your Rails app's health - This Gister

This list draws heavily upon my learnings with RailsApps Tutorials, specifically Updating to Rails 4.2.

If you are looking for a Ruby on Rails Tutorial, go RailsApps, where you can truly begin at the beginning and learn your way to deploy with confidence. We did.

Address of This Rails Applications Health Codes Gist is : https://gist.github.com/kathyonu/c9ef8190e50422bc0edc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment