Commands to keep your app healthy, Ruby and Rails gems wise.
Each command is described further below.
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 stable
brew update
brew doctor
rvm list known
The part you are most interested in this day of 20170924 reads as:
[ruby-]2.2[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
ruby-head
Now, check your ruby version, just so you know,
upgrading command comes later, make no change at this point.
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 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.
EXAMPLE: bundle update launchy
and then run tests that use Launchy, to check.
gem update
rvm list known
rvm install 2.4.1
: adjust versions as needed if Gist not current to latest Ruby or Rails versions.
pwd
: check where you are any time you wish.
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
rvm gemset use Rails5_app_name --create --default
with above command used once, below is never needed
rvm gemset use Rails5.1_app_name
ruby -v
rails -v
If all is well on rails response, skip down to
bundle update rails
otherwise do this:
open -e Gemfile
: to change Rails version to 2.4.1, 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, or ..
With new gemset selected, run:
gem install rails
NOW, you can run this one:
bundle update rails
If you ever lose track of where you are, commands wise, just type into your Terminal:
history
Now, run bundle_install
and it should be clean through up to date, no additions or changes:
bundle install
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
Returns : ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
rails -v
Rails 5.1.2
gem list
Before you push to production, check your Gemfile.lock for vulnerabilites: Is It Vulnerable ?
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 5.1.2 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 : Rails5.1_app_name
Yes, change the app_name to your app's name for easy reference.
When you upgrade to Rails5.1 simply create a new gemset, and you
can revert to the Rails5.1 gemset should the need arise.
For the first time use, we will add the create and default switches.
rvm gemset use Rails5.1_app_name --create --default
Run thhis 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.1_app_name
rvm gemset use Rails5.2_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 ?
Fire it up with:
rails s
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
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.3.0
Make sure the .ruby-version file shows 2.3.0
You can use the open -e file-address
command at the terminal_prompt.
open -e Gemfile
: add the current version of Rails, currently 5.1.2
open -e .ruby-version
: currently it reads as 2.4.1
open -e .ruby-gemset
: currently reads as Rails5.1_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, Rails5.1_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.3.0, run:
rvm list known : to show you what rubies rvm knows about.
rvm list known
If the 2.3.0 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 Rails5.1_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 Rails5.1_app_name
Check your Ruby version. Expect version to be 2.4.1
ruby -v
Check your Rails version. Expect version to be 5.1.2
rails -v
If you are not yet using Rails5.1.2, this is the point that you do so.*
gem install rails
Notice it is not, bundle install
here, we used gem install
.
Make sure you do not skip this next step.
bundle update rails
bundle install
It should be a clean response with no additions or changes.
If you have difficulties here, trash your Gemfile.lock file, then run this command again.
bundle install
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
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
..
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 will update your gems.
bundle update
Bundler now does its magic.
Follow any instructions bundler gives you while it updates.
Now check your Rails version, it should read 5.1.2
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 Nearest 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