How do I safely upgrade my ruby on rails app to use a new ruby version, using rvm?
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.
According to this blog, if you always precede commands by bundle exec you do not need to use gemsets. In that case, you would simply do
rvm --ruby-version use x.y.z
Related
I've tried everything. Every YouTube guide. Nothing simply explains how to get from point A to point B.
Homebrew
Git
RVM
and Ruby are all installed.
For some reason Rails is not.
I'm new to the whole ruby thing, and getting everything installed has been an absolute nightmare. Everything is out of date. What do I do?
Assuming you have RVM installed correctly:
1) Open Terminal.
2) Type rvm list to see which versions of Ruby you have installed.
3) Type rvm use ruby-2.3.1 if you want to use Ruby 2.3.1.
4) Type rvm gemset create Rails500 to create a gemset for Rails 5.0.0
5) Type rvm gemset use Rails500 to make Rails 5.0 your current gemset
6) Type gem install rails -v 5.0.0 to install Rails 5 to your Rails500 gemset
7) Type bundle install bring everything up to date.
Now you have Rails 5.0 running under a Rails500 gemset against Ruby 2.3.1. Remember to use ruby-2.3.1 and use gemset Rails500 whenever you start a new session in Terminal if you want to maintain multiple versions of Ruby and multiple gemsets.
To make a version of Ruby default, type the following into Terminal:
rvm --default use 2.1.1
To keep a default gemset, just rvm gemset use default and make sure you install your gems into that default gemset by use-ing it before installation.
This covers 80% of everything you'll need to know about RVM.
Also, remember to never install rbenv, because it's not compatible with RVM -- stick with one or the other.
EDIT:
It seems you're having problems with your Terminal settings as well.
1) Open Terminal
2) From the Terminal menu, select Preferences
3) Select the Command (complete path) radio button
4) Make sure the text field beneath the radio button reads /bin/bash
5) Close the Preferences dialog and restart Terminal
6) Try using Ruby 2.3.1 via RVM
If you have installed RVM,
rvm use 2.3.1
Then check gems in current gemset using,
rvm gemset list ### gives a list of gemset for ruby 2.3.1
gem list ###installed gems in current gemset
Let me know,.if it didn't work.
Assuming you have got rvm, just write:
rvm install 2.3.1
rvm use 2.3.1
Then you can install rails by gem install rails command.
I'm a little confused on using Ruby Version Manager. I was just wondering how to handle ruby updates for my web apps.
For example, I start a new Rails project and I tell RVM to use a specific version of Ruby like so:
rvm use ruby-2.0.0#my-project-name --create
Then say months down the road a new version of Ruby is released. What do I do then? Do I go back in and tell RVM to use the newer version? I want to build something that is always using the latest version of Ruby.
I'm assuming people build Rails apps, but don't always update to the newest version of Ruby and Rails?
Thanks, just starting out with all this, and trying to wrap my head around it.
There are three parts in this, Ruby, Gems and Rails Project, RVM can help organize everything in this order Ruby Interpreter/Version -> Gemset -> Rails Project
First Ruby:
You can use rvm list known to list all Ruby versions available in MRI, Rubinius, JRuby and others, after that you can install any version and interpreter like:
If you use MRI then rvm install 2.1 will install the latest in the 2.1 branch (2.1.1 being the latest).
For Rubinius rvm install rbx will install the latest stable Rubinius.
For JRuby rvm install jruby will install the latest stable JRuby.
After installing the version you're going to use, you need to specify that you're going to use it, like this for Rubinius: rvm rbx.
Second Gemset:
RVM gives you the ability to define different gemsets in each installed Ruby version that allows you to install gems for a specific project. For this Rubinius version I can:
Create a gemset like rvm gemset create latestRails.
Use a gemset rvm rbx#latestRails.
Show current Ruby/gemset rvm current.
Install latest Rails version in this gemset gem install rails.
Third Rails:
To keep Rails updated, you can use Bundler with a command like bundle update to keep all the gems updated (this are updated inside the current Ruby/gemset and the Gemfile) or a list/single gem of the project, for more info see "Bundle Update Documentation".
I hope I could help you.
I just installed rvm, ruby 1.9.3, rails 4.0 and rails 3.0
The problem is that I have to work with an application using ruby 1.9, and do not know how to select the right package. I would also like to know how to select a particular rails from the command line
One other thing: I can use Rails 4.0 for Ruby 1.9.3?
You shouldn't install two Rails versions together, this can lead to various strange behaviours, instead use Gemsets (decribed below).
To install specified Ruby version: rvm install 1.9.3-p385 - yes, you can even specify pathlevel.
To use that Ruby: rvm use 1.9.3-p385 - or just rvm use 1.9.3 if you don't have other 1.9.3 versions.
You should also create Gemset for your app so you won't pollute your rvm's specific ruby install with gems from other projects which you will probably create later.
To do that write rvm gemset create put_name_here, you will have now new Gemset in scope of your selected rvm's Ruby install.
To use that Gemset write rvm gemset use put_name_here. - You can also do rvm use 1.9.3#put_name_here - that will select both Ruby and Gemset with one command.
Now you can do bundle and all gems will be installed to specified Gemset under chosen Ruby version.
To make your life easier you can create in root of your app two files containing:
.ruby-version
1.9.3-p385
.ruby-gemset
put_name_here
And since then rvm should automatically change Ruby version and select specified Gemset when you will enter that directory.
To list installed Rubies and created Gemsets: rvm list and rvm gemset list (that shows Gemsets under current Ruby only).
And yes, you can use Rails 4.0 with Ruby 1.9.3
Also, you should check rvm homepage, everything is well described there.
I am trying to install Rails into a new rvm gemset.
I tried the following:
rvm gemset create rails-4.0
output: gemset created rails-4.0
Next I did:
rvm 2.0.0#rails-4.0
rvm gemset list:
gemsets for ruby-2.0.0-p0 (found in /Users/me/.rvm/gems/ruby-2.0.0-p0)
(default)
global
=> rails-4.0
rails -v
Rails is not currently installed on this system. To get the latest
version, simply type:
$ sudo gem install rails
Do the rvm commands I listed not install rails 4.0?
This command:
rvm gemset create rails-4.0
is creating basically a directory structure to hold the gems. You could have just as easily called it something other than "rails-4.0" like "foo" and it would be the same behavior.
This command:
rvm 2.0.0#rails-4.0
Switches to Ruby 2.0.0 and tells it to use the new gemset named rails-4.0. Again, that could be "foo" or whatever you called it.
Now, to get Rails 4.0.x, you'd do:
gem install rails --version=4.0
As Barrett pointed out earlier, to get a pre/beta/rc release, you can specify the whole version string, e.g. gem install rails --version=4.0.0.rc2.
Don't sudo, because you shouldn't sudo with rvm, even though it tells you to. With the "system ruby" (ruby not installed by rvm), it may be installed as root, so you need superuser (su) access (superuser do or "sudo") to do that. But, rvm has you install things as the current user, therefore you don't need to sudo.
In addition to the usage tips above, if you don't specify the gem version you won't get the beta or pre version, so to get rails 4, you need:
gem install rails --version=4.0.0.rc1
Maybe try InstallRails?
http://installrails.com/ is a guide for installing rails that deals with these issues for various Operating Systems and setups. It might prove helpful for something like this.
Other answers shows instructions for creating the gemset using default ruby version.
For creating a gemset and use it with different ruby version please follow the instructions below:
Let's say on my machine I have following ruby versions installed and 2.2.0 is the default.
=*ruby-2.2.0 [ x86_64 ]
ruby-2.2.1 [ x86_64 ]
ruby-2.2.3 [ x86_64 ]
Now I have forked a repository from Github and want to test out the repo's code with Rails 5 (edge version) and Ruby 2.2.3 (the latest stable version at the time of this writing). And I prefer using gemsets so I ran following commands:
rvm use 2.2.3#forked-repo --create
That's actually a shortcut for
rvm 2.2.3
rvm gemset create forked-repo
Next I would run following command to install bundler:
forked_repo_root$ gem install bundler
forked_repo_root$ bundle
That should install the gems used in your forked-repo in the gemset created above.
Reference: https://rvm.io/gemsets/creating
I got confused of some Rails' concepts like: gemset, rubygems, bundler . I have following three questions:
1. After I installed the RVM tool, what are the correct steps to setup the development enviroment for creating a rails project (say rails v2.3 project)
2. What is the difference between "gem install XXX" and "bundle install"? Can I understand it in the way that "bundle install" install all gems needed in the app at once while "gem install XXX" only install the specified "XXX" gem ? Are there any other difference? Why not use bundler to install specific rails then?
3. If I want to use rails v3.0 for project_one, and use rails v2.3 for project_two. How to create the two projects with the specific rails versions? How about different ruby versions for different projects? Do I only need to specify the needed version in Gemfile or install the needed version under the project path?
RVM allows you to create different gemsets alongside different ruby versions.
You can install different versions of ruby with rvm install.
rvm install 1.8.7
rvm install 1.9.2
rvm list known will tell you the available ruby implementations you can install.
Say, you have two projects: project_one and project_two, and both of them have different gem dependencies. So you'll want to create two empty gemsets with, say, Ruby 1.9.2.
rvm gemset create 1.9.2#project_one
rvm gemset create 1.9.2#project_two
To use project_two's gemset, you can use rvm use to select the gemset.
rvm use 1.9.2#project_two
You can also add the above command into a file called .rvmrc in the root path of your rails application, which rvm will load automatically whenever you cd into the app's root directory.
If you want to use Rails 2.3.8 for project_one,
rvm use 1.9.2#project_one
gem install rails -v 2.3.8
and Rails 3.1.0 for project_two,
rvm use 1.9.2#project_two
gem install rails -v 3.1.0
The difference between gem install and bundle install is that gem install installs only the specified gem into your gemset, while bundle install installs all the gems located in your app's Gemfile.
1) If you have a rvm setup I propose add in in your app file .rvmrc
and in that file:
rvm --create ree-1.8.7-2011.03#myappname
This will alway use specify version of ruby (in that case 'ree-1.8.7-2011.03') and all gems will be installed in rvm gemset named: myappname. This file will always make sure every time you go to that folder from bash_console it will point rvm to correct environment.
2) If you have rvm setup then:
gem install XXX creates gem in specify rvm gemset or if not global rvm gemset
sudo gem install XXX will add gems to you Global gems
Like you said, you should always use Bundle install, and group gems for development,test, production.
3) This can achieve like I said in point 1) just create this file in your app