RVM and RubyGems
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.
DO NOT use sudo...
to work with RVM gems. When you do sudo you are running commands as root, another user in another shell and hence all of the setup that RVM has done for you is ignored while the command runs under sudo (such things as GEM_HOME, etc...). So to reiterate, as soon as you 'sudo' you are running as the root system user which will clear out your environment as well as any files it creates are not able to be modified by your user and will result in strange things happening. (You will start to think that someone has a voodoo doll of your application...)
You can see the gem directory of the currently selected ruby using the gemdir action:
∴ rvm 1.9.1 ∴ rvm gemdir /Users/wayne/.rvm/gems/ruby-1.9.1-p378
To change to the currently selected Ruby's gem directory, use a subshell:
∴ rvm 1.9.1 ∴ cd $(rvm gemdir) ∴ pwd /Users/wayne/.rvm/gems/ruby-1.9.1-p378
If this is something you do frequently you can put the following bash function in your ~/.bash_profile or ~/.zshrc:
# Thanks for the awesome idea batasrki
function gemdir {
if [[ -z "$1" ]] ; then
echo "gemdir expects a parameter, which should be a valid RVM Ruby selector"
else
rvm "$1"
cd $(rvm gemdir)
pwd
fi
}
Then switching is very simple:
∴ gemdir 1.8.6 /Users/wayne/.rvm/gems/ruby-1.8.6-p399 ∴ pwd /Users/wayne/.rvm/gems/ruby-1.8.6-p399 ∴ gemdir 1.9.1 /Users/wayne/.rvm/gems/ruby-1.9.1-p378 ∴ pwd /Users/wayne/.rvm/gems/ruby-1.9.1-p378