I have been using RVM to manage my Rubies and gems.
When I first installed RVM, the Ruby version that I installed was 1.9.2-p0. I recently installed Ruby 1.9.2-p136, which created a new Ruby in the RVM.
My problem is I want to use the latest version of Ruby but all of the gems I installed were installed under the 1.9.2-p0 directory, because RVM keeps gems completely separate between Rubies, and I want to be able to use those gems with my new version, p-136 without having to reinstall them all.
Is there a way I can get my gems from my p-0 Ruby to work with my p-136 Ruby?
You can use copy in rvm
$ rvm gemset copy 1.9.2-p0 1.9.2-p136
See more about the rvm copy command
This is the fastest way to get your gems moved over and it wont reinstall everything, just copy them over. But once you've got that squared away I'd do as the others are suggesting and start using gemsets. It's a nice way to group the gems you use in your projects.
This might help: http://rvm.io/gemsets/initial/
Basically, if you setup a global gemset configuration, those gems will be used for every ruby version you install.
You need to check out gemsets and export your current gems.
rvm gemset export
Read the gemset docs for more information.
You can copy a gemset from one ruby to another.
rvm copy
$ rvm gemset copy 2.1.1#rails4 2.1.2#rails4
Related
I worked on some project when in some moment I have to change Ruby version for some other project. Now when I want to go back to first project, I'm getting some errors because of Ruby version. The question is how to change Ruby version(currently I'm on RVM-installed Ruby 2.5.1) and want to back to Ruby 2.4.5 but it wasn't installed via Rvm or Rbenv, just clean installation.
I know how to change Ruby version via Rvm, but how to change to version which is not installed with any addition (Rvm or Rbenv)
Even though this doesn't answer your question directly, I would recommend against using both RVM Ruby and system Ruby together. RVM was not designed to work that way and every issue arising from this kind of installation would be quite difficult to debug, particularly if you are a beginner.
So the easiest way to go would be to remove the system Ruby completely and create a 2nd RVM gemset for your other project. (This is how RVM is intended to be used, actually.)
See doc: https://rvm.io/gemsets/creating
https://rvm.io/gemsets/basics
If you have more then one projects with different ruby versions then we need to use rvm gemsets to avoid conflicts.
Steps to be followed:
rvm gemset create sriharsh
rvm use 2.2.1#sriharsh --create
rvm gemset list (to check list of gemsets)
rvm list (list of rvm rubbies)
However, if you are using Bundler then you don't need to use RVM Gemsets. Prepending any command with bundle exec will execute it in the context of the project's Gemfile.
For ex:
bundle exec rails s
I have installed a lot of gems in the default and global gemsets by mistake. I want to remove all gems that were installed in those gemsets by me. Is there a way do to this?
If you are using RVM and want to remove all the gems installed there, you can use
rvm gemset empty <gemset>
This will basically remove all gems from the gemset you specify, then you'll have a blank slate to start over installing things that you only care about.
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.
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 really confused by the explanations given in RVM website. The relation between different ruby interpretors and gemsets are not clear to me. According to me, it is like this -
My Account in my Mac have one rvm
That rvm installs and manages set of different versions of ruby interpretors.
each ruby version has set of gemsets.
Am i getting things clear... Any more amount of explanations are welcome. I am in a position to work on (Ruby 1.8.7 + rails 2.3.8 and its dependencies) and (Ruby 1.9.2 and Rails 3.0 and its dependencies)...
If any one is well versed with handling many ruby versions and gemsets with the help of rvm, please explain to me... thanks for the help
Here is how I like to do it...
Install a ruby with RVM
Switch to/use that ruby
Create a gemset for a project
Switch to/use that gemset
Install gems needed
create an alias that points to my chosen ruby & gemset
switch to/use that new alias (again, associated w/ a project)
Do this as many times necessary for your different projects that you want to keep separate from eachother.
Example:
$ rvm install ruby-1.9.2
...
$ rvm list
rvm rubies
=> ree-1.8.7-head [ i386 ]
ruby-1.9.2-head [ i386 ]
ruby-1.9.2-preview3 [ i386 ]
$ rvm use ruby-1.9.2-preview3
info: Using ruby 1.9.2 preview3
$ rvm gemset create my_project
info: Gemset 'my_project' created.
rvm gemset use my_project
info: Now using gemset 'my_project'
$ gem install httparty
When you HTTParty, you must party hard!
Successfully installed crack-0.1.8
Successfully installed httparty-0.6.1
2 gems installed
$ rvm alias create my_project ruby-1.9.2-preview3#my_project
info: Creating alias my_project for ruby-1.9.2-preview3#my_project.
info: Recording alias my_project for ruby-1.9.2-preview3#my_project.
$ rvm use my_project
info: Using ruby 1.9.2 preview3 with gemset my_project
$ ....
Now I have an entire environment dedicated to a particular project. This is great because I can experiment with all sorts of different gems/versions without worrying about stomping all over other projects that have very specific requirements.
Good luck!
To add onto Brian's answer above, you can also use .rvmrc files to dynamically switch gemsets when entering new project directories.
simply run the following:
rvm rvmrc create ruby-1.8.7-p358#my_project
This will help stop confusion which I had when switching and forgetting to change gemsets
UPDATE
.rvmrc files are in the process of being dropped for the newer .ruby-version file
see discussion here: https://gist.github.com/fnichol/1912050