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
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 am currently running the following on OSX 10.6.8 and am trying to understand gemsets and gems.
Ruby 1.9.3-p194
Rails 3.2.8
RVM 1.15.6
When I look in .rvm/gems/ I see several gemset directories. Inside each one there is a gems directory. Now, whats the relationship between the non-'#' gemset and the #global gemset?
From the documentation:
Interpreter global gemsets
RVM provides (>= 0.1.8) a #global gemset per ruby interpreter.
Gems you install to the #global gemset for a given ruby are available
to all other gemsets you create in association with that ruby.
This is a good way to allow all of your projects to share the same
installed gem for a specific ruby interpreter installation.
To expand on this, the gemset without the #global is the default gemset for that Ruby version. It is essentially a gemset with no name. The #global gemset, however, is special for the reasons outlined in the docs above.
I was having a problem with RVM, so I uninstalled and re-installed it.
The truth is I actually tried rbenv, but that didn't work out for me so I am trying to get rvm up and running again - without having to install duplicate versions of Ruby.
I have at least 1 existing version of Ruby installed:
ruby --version
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]
But when I do rvm list I get a blank list:
bash-3.2$ rvm list
rvm rubies
# Default ruby not set. Try 'rvm alias create default <ruby>'.
# => - current
# =* - current && default
# * - default
So my question has two parts:
How do I see all the versions of Ruby on my system (given that rvm is not showing me any)?
How do I associate the new RVM install with the existing versions of Ruby?
Or am I better off removing all existing versions of Ruby and re-installing everything? That seems like a pain in the ass though.
You can add an existing ruby to rvm using:
rvm mount /path/to/ruby
or:
rvm automount
but be careful as ruby installed in system might have hardcoded paths for gems - so gemsets would not work with it.
There is also new way of adding binary rubies (already compiled), for list of available builds for your platform run:
rvm list remote
and you can install those rubies using:
rvm mount -r 1.9.3
This might be default way of installing ruby to avoid compilation in next stable release of RVM - but it will work only for ruby 1.9.3+.
You don't want to associate RVM with an existing Ruby, you just want to install a new Ruby.
You don't want to remove the system Ruby, either; OS X depends on it.
Install a new 1.8.7 under rvm, this way you can associate your own gemsets with it. Let OS X manage the default system Ruby, you just ignore it and use your own, managed solely by rvm.
(If you decide to go the rvm route.)
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
I've run into a lot of issues whilst attempting to install RVM on Ubuntu 9.10. Here's the steps I've tried doing:
install ruby (via ruby site, no package manager)
download rvm
install rvm (make edit to .bashrc)
use rvm to install ruby version & gems
Is there any crucial step that I seem to be missing?
Be sure to have selected an installed ruby (the --default portion tells rvm you want this ruby to be your default ruby version). Something like:
rvm --default use 1.9.2
Also this command will tell you which ruby is currently selected:
rvm list
And hopefully you'll see something like:
rvm rubies
ruby-1.9.2-p0 [ x86_64 ]
=> ruby-1.8.7-p302 [ x86_64 ]
At this point, you'll be able to install gems and hopefully have a successful rvm install and working environment.
I've had issues in the past where I didn't have an rvm ruby selected and was still working with my distribution's ruby and gems and got mixed up easily. Make sure you're ruby and gem commands are working out of your ~/.rvm folder whith the following commands:
which ruby
which gem
Good luck!
What are the issues you're running into? Sometimes I forget to switch into the correct rvm environment (e.g. rvm ree), so it helps to place a .rvmrc file in project directories.
I would start off by removing ubuntu's ruby installation so that you don't have to worry about conflicts (although rvm will setup your PATH correctly). Following the instructions at RVM, run the following command to install rvm,
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
and then install system dependencies as listed in rvm notes. and then install the specific ruby version you want (e.g. rvm install ree or rvm install 1.9.1)
Important : for a good installation try this :
type rvm | head -n1
Must return : rvm is a function
else add this line
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"
in your profile.