How to upgrade ruby version of ruby on rails app u

2019-04-14 09:45发布

How do I safely upgrade my ruby on rails app to use a new ruby version, using rvm?

1条回答
再贱就再见
2楼-- · 2019-04-14 10:39

Suppose your app is my_app and you are using ruby version a.b.c and want to go to ruby version x.y.z.

Step 0

Before starting, make sure you have the up to date version of rvm

rvm get stable
rvm reload

Step 1

First if you do not have a gemset for your current ruby version create one and make it the default. This gives you an easy way to go back if your upgrade breaks your tests. If you do not want to do this, go to step 2.

rvm gemset create my_app_abc

The switch to that gemset and install the gems into that gemset, and make it the default gemset for the directory

rvm a.b.c@my_app_abc
bundle
rvm --ruby-version use a.b.c@my_app_abc

Step 2

Now upgrade to the new ruby version and create a gemset for it.

rvm install x.y.z
rvm use x.y.z
rvm gemset create my_app_xyz
rvm x.y.z@my_app_xyz

It is considered best practice to specify the ruby version in your Gemfile so make sure you have ruby 'x.y.z' at the top of your Gemfile. Then

gem install bundle
bundle

This is where the fun can start, you may get errors at this point and use a combination of following the error instructions or googling for help, etc to solve them. When you can bundle successfully, then run all your tests.

When your tests have all passed, then you have successfuly upgraded. If you get stuck, you can go back to your old installation, using rvm a.b.c@my_app_abc.

Once you are happy with your new installation then do

rvm --ruby-version use x.y.z@my_app_xyz

to make this the default setup for this app. This means when you change into this app from other projects, it will automatically load ruby version x.y.z and the corresponding gemset.

查看更多
登录 后发表回答