I understand that rvm allows us to run multiple versions of ruby. Are ruby gems installed to a specific version of ruby? Say I upgraded to the latest version of ruby 2.1.1 and want to use that as my default, do I have to reinstall the ruby gems from the earlier version of ruby to this version?
If you use rvm install, you will have to install your gems anew. If you use rvm upgrade, the gems will be migrated if possible.
Check out the RVM documentation:
RVM creates a new completely separate gem directory for each version of ruby. In addition you can separate this further and have a set of gems per project/application/gerbil color... see the gemsets for more details on using sets of gems. [...]
rvm --default use <RUBYVERSION>
For example,
rvm --default use 2.1.1
You can check this. And check out RVM Documentation too.
Related
What's the best way to upgrade to Ruby 2.3 through rvm while keeping all your gems installed on previous version (e.g. json, nokogiri, etc)?
EDIT
This question has an answer here: RVM: How to use gems from a different ruby?
$ rvm gemset copy $oldversion 2.3.0 ## Assign or replace $oldversion with old version name
ORIGINAL
Before installing Ruby 2.3, get a list of your installed gems and their versions using gem list. Then, after you install Ruby 2.3, use rvm to set 2.3 as the new default:
$ rvm install 2.3.0
$ rvm --default use 2.3.0
If you use Bundler, gem install bundler and then bundle install in all your project directories. This should install all of the gems relevant to your work.
If you don't use Bundler, or if you have gems installed that aren't part of any project's Gemfile, then you will want to go through the list of gems and their versions that you made earlier and gem install each of them, using -v to specify the version.
I am making a script to install the latest stable ruby using rvm. I use:
rvm install ruby --latest
But the problem is, since I do not know which version is going to be installed, I do not know how to use rvm use to set it as the default ruby version.
How could I solve this?
You can do
rvm use ruby --latest --default
I just installed Ruby 2.0.0 using rbenv and set it to the global ruby version for my system. Since 2.0 is compatible with 1.9.3, I tried to start up a Rails project with it, but got the following error. I did rbenv rehash after installing 2.0
The `rails' command exists in these Ruby versions:
1.9.3-p327
Does this mean that every gem I installed on my system with 1.9.3 has to be reinstalled if I wish to use it with 2.0?
As seen here:
You need to reinstall bundler for each version of Ruby you use. See Ruby versions where you have it installed:
rbenv whence bundle
See your current version:
rbenv version
Install bundler for that version, if missing:
gem install bundler
Yes. Rbenv (and RVM) have separate "gem home" directories for each installed version of Ruby. There may be ways to symlink certain directories to get them to share, but this will likely lead to problems, particularly with gems that include native C extensions, which may or may not compile and run cleanly in multiple versions.
If you have a Gemfile, easiest thing is to just bundle install again for Ruby 2.0, giving you duplicate copies of many gems and Ruby-2.0 compiled versions of any native gems.
Another solution to this is to copy (or reinstall) the gems from your previous version to the newly installed version. How to do that is answered in detail in this question, which has two scripts -- one to install from local cache, one to reinstall from the internet (mine).
I've been using the default system ruby version 1.8.7 without RVM for a few rails projects and have not run into any problems. I just recently installed RVM, and after running rvm requirements I get this output:
To use an RVM installed Ruby as default, instead of the system ruby:
rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.8.7
I believe what these commands do are to install the same gems that have already been installed using the system ruby under the RVM installed ruby.
My questions are, am I right in what these commands do? and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The one thing that springs to mind is, if you use the system Ruby, you'll use it slightly differently that RVM's Rubies--for example, you'll likely need to use sudo to install gems. Furthermore, you won't be able to use many of RVM's features, like gemsets, with the system Ruby.
Well one reason I can think of is that you don't wanna worry about your system not working even if the system ruby gets updated.
My questions are, am I right in what these commands do?
You are right in what they do. The first command installs Ruby 1.8.7, the second command installs all the gems currently install on your system Ruby installation in the new RVM Ruby 1.8.7 installation, and the third command sets your default version of Ruby to be the RVM Ruby 1.8.7.
and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The second command is actually more of about convenience than necessity. Yes, the gems install in the RVM 1.8.7 will be completely separate from the ones installed in the system version of Ruby; however, if you didn't run the second command, you're RVM 1.8.7 would start out with almost no gems (only the defaults). That means that you would need to go through and manually install the gems that you need to get your project up and running. Instead of doing that, the second command allows you to just install the same gems you've already installed in the system version of Ruby to the RVM 1.8.7 version—it doesn't migrate them, it just makes a copy of them. After the second command, there are two distinct sets of the exact same gems: one in the system Ruby and one in the RVM 1.8.7 Ruby. So, if you were to update gems in either of the Rubies, they would get updated, but the other version's gems would be unaffected.
Hope this helps answer your question.
I am trying to setup Ruby 1.9.2-p180 on my system for project specific purposes. I already have Ruby 1.9.2-p134 and Ruby 1.8.7 with me.
Do I need to replace Ruby 1.9.2-p134 with Ruby 1.9.2-p180 or can both co exist?
I'm making use of Ubuntu 10.04 OS.
Thank you..
That's exactly what RVM is for.
rvm install 1.9.2-p180
Then to use it…
rvm use 1.9.2-p180
You can also use .rvmrc to configure projects per-directory and set the rvm default to whichever you prefer.
To list installed Ruby versions…
rvm list
:)